Module 4: Strings in Python
Creating Strings
A string is text — names, messages, column labels in a spreadsheet. In Python, you put text inside quotes.
About 8 minutes
Single and double quotes
Both "hello" and 'hello' work the same. Use whichever quote is easier when your text contains the other kind.
Example code
message = "Hello"
name = 'Python'
print(message, name)
# Apostrophe inside double quotes:
print("It's a great day")Multiline strings
Triple quotes """ ... """ let you write text across many lines.
Example code
poem = """Roses are red Violets are blue Python is fun""" print(poem)
Quotes
" or '
Text inside
Your characters
str type
Python stores it
Practice
Create a string with your name and a multiline string with two favorite foods. Print both.
Key takeaways
- Strings hold text; use " " or ' '.
- Triple quotes for multiline text.
- Strings are type str.
Quick check: Creating Strings
Question 1 of 2
Which creates a valid Python string?