The simplest form of text sequences in Python is a str
or strings.
To write a string in Python you have 4 options:
- Using single quotes:
myStr = 'this allows "double" quotes inside'
- using double quotes:
myStr = "this allows 'single' quotes inside"
- Using triple single quotes:
myStr = '''Three quotes allows
for multiline strings.
Cool right?'''
- Using triple double quotes:
myStr = """Three quotes allows
for multiline strings.
Isn't that even cooler?"""
Strings are considered 'immutable' meaning they can not be changed; however, two strings can be concatenated together using the +
operator.
Example:
firstName = 'Jane'
lastName = 'Doe'
fullName = "My full name is: " + firstName + " " + lastName + "."
Instructions:
Mini-Mad-Lib:
- Assign strings to each variable.
- Then concatenate everything together in the
mySentence
variable