Lesson 2 - Strings

Strings in Python

.strip() to remove extra spaces. Example: print("     Python is fun     ".strip()) > Python is fun
.lower() to change case to lowercase. Example: print("Python is fun".lower()) > python is fun
.upper() capitalize all letters. Example: print("python is fun".upper()) > PYTHON IS FUN
.capitalize() capitalize only first letter of sentence. Example: print("python is fun".capitalize()) > Python is fun
.title() capitalize only first letter of each word. Example: print("python is fun".title()) > Python Is Fun
.replace() to swap words. Example: print("python is fun".replace("python", "coding")) > coding is fun
len() for counting. Example: print(len("python is fun")) > 13

print("Hello, world!")

💡 Change "world" to your name.


print("I" + " love" + " Python")

🎯 Challenge: Make a new sentence about your favorite food.


Print this:

😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊


Count Letters

💡 How many letters in this sentence?
What a wonderful world


print("I like cats")

Change "cats" with "dogs"


Count Letters - 2

Write how many letters are in each word: banana, strawberry, cat


message = " Python is FUN!!! "

count - is total letters of message above without space.
Print this: print("This message has", count, "letters (no spaces).")

Back Next Lesson