Python lesson 3
Strings
Text is everywhere in Python. Learn to combine, change, and measure it!
Strings Are Text
A string is any text wrapped in quotes. You can join two strings together with + (called concatenation), make them UPPERCASE or lowercase, and count how many letters they have with len()!
name = "Alex"
greeting = "Hello, " + name
print(greeting) → Hello, Alex
first = "Hello"
last = "Python"
print(first + " " + last)
How Long Is It?
word = "Python"
print(len(word))
print(word.upper())
Join Two Strings
Click Run to join two strings into one message using the + sign!
Hint: Click Run! The + sign joins the two strings into one.
greeting = "Hello, " + "world!"
print(greeting)
UPPERCASE and Lowercase
Run this code to see .upper() and .lower() in action. Then change "Python" to YOUR name!
Hint: Change "Python" to your own name, then click Run to see it in uppercase and lowercase!
word = "Python"
print(word.upper())
print(word.lower())
Count the Letters
Run the code to see how many letters are in a word. Then change "coding" to YOUR name!
Hint: len() counts the characters in the string. Change "coding" to your own name and run again!
word = "coding"
print("Letters:", len(word))
What you can do on CodeIt
Run the example, change one part, and use the result to check your understanding before moving to the next lesson.