Lesson 6 of 16
Lesson Progress: 0%
Code Example
# Joining two simple words
print("Data" + "Science")
# Adding a space between words
print("Python" + " " + "Programming")
# Building a simple phrase
print("Ice" + "Cream")
# Adding punctuation to a word
print("Warning" + "!")Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
+ to join text." ".print() shows the joined words on the screen.print("Data" + "Science") joins two words." " in the middle.print("Python" + " " + "Programming") adds a space.print("Ice" + "Cream") makes one new word.! to words.print("Warning" + "!") adds an exclamation mark.Code Example
# 1. Repeating a word multiple times
print("Hello" * 3)
# 2. Creating a visual divider
print("-" * 10)
# 3. Repeating a single character for emphasis
print("A" * 5)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
* isn't just for math; it can also copy words!"Hello" * 3 tells Python to write "Hello" three times in a row."-" * 10, to separate your work.print() helper.Code Example
# Indexing - Access a specific character
# Gets the first letter "P"
print("Python"[0])
# Gets the fifth letter "o"
print("Hello"[4])
# Access the first item in the list
pets = ["Cat", "Dog", "Bird", "Fish", "Hamster"]
print(pets[0])
# Access the fourth item in the list
cities = ["New York", "London", "Paris", "Tokyo", "Berlin"]
print(cities[3])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[ ] with a number to pick one letter or one item.[0] means the first one.Code Example
# Slicing - Access a range of characters
# Gets "eat" (indices 1, 2, and 3)
print("Weather"[1:4])
# Gets "can" (indices 2, 3, and 4)
print("Ocean"[2:5])
# Gets ["blue", "green"]
colors = ["red", "blue", "green", "yellow"]
print(colors[1:3])
# Gets ["apple", "banana"]
fruits = ["orange", "apple", "banana", "grape"]
print(fruits[1:3])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[ ], we use two numbers with a colon in the middle to show where to start and stop.Code Example
# Step Slicing - Reverse a string
# Reverses the word to "pots"
print("stop"[::-1])
# Reverses the sentence
print("Step on no pets"[::-1])
# Step Slicing - Reverse a list
games = ["chess", "soccer", "tennis"]
print(games[::-1])
# Step Slicing - Reverse a list
fruits = ["apple", "banana", "orange"]
print(fruits[::-1])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[::-1] to flip things backward.-1 to tell Python to walk backward.Code Example
# More slicing
# stop at the second to last character
print("Weather"[:-2])
# stop at the third to last character
print("Weather"[:-3])
# start at the second character
print("Weather"[1:])
# start at the third character
print("Weather"[2:])
# 1. Stop at the third element
langs = ["Python", "Java", "C++", "Ruby", "Swift"]
print(langs[0][0:2])
# 2. Reverse the list
words = ["Apple", "Bread", "Candy", "Donut", "Email"]
print(words[::-1])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[:-2] means Python shows everything except the last two characters.[:-3] means Python shows everything except the last three characters.[1:] means Python starts at the second character and shows the rest.[2:] means Python starts at the third character and shows the rest.langs[0][0:2] first picks the first word in the list, then shows only its first two letters.words[::-1] tells Python to go through the list backwards.Code Example
# Convert to all uppercase letters
print("hello".upper())
print("fast car".upper())
# Convert to all lowercase letters
print("PYTHON".lower())
print("DO NOT YELL".lower())
# Capitalize every word (Title Case)
print("jane doe".title())
print("the big bridge".title())
# Capitalize only the first letter
print("apple".capitalize())
print("today is sunny".capitalize())Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.upper() makes all letters BIG..lower() makes all letters small..title() makes each word start with a big letter, and .capitalize() makes only the first letter big.Code Example
# Removing spaces from both ends
print(" Hello ".strip())
# Removing stars from both ends
print("***Welcome***".strip("*"))
# Removing dashes from both ends
print("---Good job!---".strip("-"))Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.strip() helper is like a vacuum cleaner that sucks up extra spaces from the start and end of your words.* or dashes -, you just put them inside the parentheses.Code Example
# Returns 2 (the index of the first "t")
print("Python".find("t"))
# Returns 7 (the index where "World" starts)
print("Hello World".find("World"))
# Find the index for "Cherry"
fruits = ["Apple", "Banana", "Cherry"]
print(fuits.find("Cherry"))
# Returns 2 (there are two "p"s)
print("apple".count("p"))
# Returns 3 (there are three "e"s)
print("bee keeper".count("e"))
# Counting how many times "Apple" appears in the list
fruits = ["Apple", "Banana", "Cherry", "Apple"]
print(fruits.count("Apple"))Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.find() tells us where a word or letter starts (it gives a number).0 means the first spot..count() tells us how many times something appears.Code Example
# Changing one word to another
print("I like cats".replace("cats", "dogs"))
# Fixing a name
print("Hello Sam".replace("Sam", "Alex"))
# Swapping a word in a short sentence
print("Good morning".replace("morning", "night"))
# Replacing a character in the second list item
colors = ["dark", red", "blue"]
print(colors.replace("dark", "bright"))
print(colors)
# Replacing "Windy" with "Hot" in the third list item (index 2)
weather = ["Sunny", "Rainy", "Cold Day", "Windy", "Cloudy"]
print(weather.replace("Windy", "Hot"))
print(weather)Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.replace() helper works like a magic wand that swaps one piece of text for another.Code Example
# .split() - Breaking a string apart
# Splits into parts by the space
print("Small medium large".split())
# Splits into parts by the hyphen
print("State-of-the-art".split("-"))
# Splits into parts by the slash
print("2025/12/25".split("/"))Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.split() breaks a sentence into smaller parts.- or /.print() shows the pieces on the screen.Code Example
# .join() - Combining characters within a string
# Connects characters with a dash
print("-".join("12345"))
# Connects characters with a dot
print(".".join("SOS"))
# Connects characters with a star
print("*".join("MAGIC"))
# Joining a list of words with a hyphen
print("-".join(["Red", "Green", "Blue"]))
# Joining a list of words with a comma
print(", ".join(["Apple", "Banana", "Cherry"]))Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.join() helper acts like glue to stick different parts together into one long string."-" or a star "*", is the "glue" that goes between each part.S.O.S..join(), and then the things you want to stick together inside the parentheses.