Lesson 6 of 16
Lesson Progress: 0%
# 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.# Repeating a word multiple times
print("Hello" * 3)
# Creating a visual divider
print("-" * 10)
# 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.# 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.# Slicing - Access a range of characters
# (indices 1, 2, and 3)
print("Weather"[1:4])
# (indices 2, 3, and 4)
print("Ocean"[2:5])
colors = ["red", "blue", "green", "yellow"]
print(colors[1:3])
fruits = ["orange", "apple", "banana", "grape"]
print(fruits[1:4])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.# Step Slicing - Reverse a string
# Reverses the word
print("stop"[::-1])
# Reverses the phrase
print("Step on no pets"[::-1])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[::-1] to flip things backward.# Step Slicing - Reverse a string
# 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.# More slicing
# stop at the second to last character
print("Weather"[:-2])
# stop at the third to last character
print("Weather"[:-3])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.# More slicing
# start at the second character
print("Weather"[1:])
# start at the third character
print("Weather"[2:])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
[1:] means Python starts at the second character and shows the rest.[2:] means Python starts at the third character and shows the rest.# More slicing
# Stop at the third element
langs = ["Python", "Java", "C++", "Ruby", "Swift"]
print(langs[0][0:2])Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
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.# 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:
words[::-1] tells Python to go through the list backwards.# 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())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.# Capitalize every word (Title Case)
print("jane doe".title())
print("the big bridge".title())Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.title() makes each word start with a big letter.# 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:
.capitalize() makes only the first letter big.# 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.# Returns 2 (the index of the first "t")
print("Python".find("t"))
# Returns 7 (the index where "World" starts)
print("Hello World".find("World"))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, known as the index)..find() tells us the index of a word or letter in a list (it gives a number).# Returns 2 (there are two "p"s)
print("apple".count("p"))
# Returns 5 (there are five "e"s)
print("bee keeper".count("e"))Instructions
▼ ← Click the triangle to hide or reveal instructions.Python Code Editor
Task Incomplete
Editor Input:
Editor Output:
.count() tells us how many times something appears.0 means the first spot.# 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"))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.# 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.# .join() - Combining characters within a string
# Connects characters with a dash
print("-".join("12345"))
# Connects characters with a dot
print(".".join("SOS"))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.# Connects characters with a star
print("*".join("MAGIC"))
# Joining a list of words with a hyphen
print("-".join(["Red", "Green", "Blue"]))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.# 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(), and then the things you want to stick together inside the parentheses.Test Incomplete