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 funlen() 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:
😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊😊
💡 How many letters in this sentence?
What a wonderful world
print("I like cats")
Change "cats" with "dogs"
Write how many letters are in each word:
"banana" →
_
"strawberry" → _
"cat" → _
message = " Python is FUN!!! "
Print this:
print("This message has", count, "letters (no
spaces).")