String
Part of the Fundamentals section of Coddy's Python journey — lesson 5 of 77.
A character is a single letter, digit, or symbol (for example: 1, 6, %, b, p, ., T, etc.). Python has no separate char type — a single character is simply a string of length 1.
The str (string) type is a sequence of one or more characters.
To initialize a string value in a variable, enclose it within single or double quotation marks:
s1 = 'This is a string'
s2 = "This is also a string"In the above example, two string variables are initialized, named s1 and s2.
Challenge
BeginnerStore the string I am learning to code with Coddy! in a variable named coddy.
Be sure to store the exact string value with correct casing.
Cheat sheet
A char is a single character (e.g., 1, 6, %, b, p, ., T).
A str (string) is a sequence of multiple characters.
To create a string variable, enclose the text in single or double quotes:
s1 = 'This is a string'
s2 = "This is also a string"Both single and double quotes are valid for creating strings in Python.
Try it yourself
# Type your code below
coddy = ?
# Don't change the line below
print(f'coddy = "{coddy}"')This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2