• Home
  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
    • Expert React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
      • Expert Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
      • Expert JavaScript Developer
    • React
      • Introduction to React
      • React Developer
      • Expert React Developer
    • Linux
      • CyberSecurity - Introduction to Linux
      • CyberSecurity - Linux Administrator
      • CyberSecurity - Expert Linux Administrator
    • Active Directory
      • CyberSecurity - Introduction to Active Directory
      • CyberSecurity - Active Directory Administrator
      • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Brainstorm

Courses

  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React
    • Introduction to React
    • React Developer
    • Expert React Developer
    • Professional Master React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator

Newsletter

Subscribe to our monthly newsletter, for a quick update on Python, JavaScript, React news

© 2024 - 2026 STEMTrainingGrounds. All Rights Reserved.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • Python can join words together.
  • We use the plus sign + to join text.
  • Each word must be inside quotes " ".
  • print() shows the joined words on the screen.
  • print("Data" + "Science") joins two words.
  • If you want a space between words, you add " " in the middle.
  • print("Python" + " " + "Programming") adds a space.
  • You can build short phrases by joining words.
  • print("Ice" + "Cream") makes one new word.
  • You can also add symbols like ! to words.
  • print("Warning" + "!") adds an exclamation mark.
  • Each line joins text and prints the result.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • In Python, the star symbol * isn't just for math; it can also copy words!
  • When you put a star and a number after a word, Python repeats that word for you.
  • For example, "Hello" * 3 tells Python to write "Hello" three times in a row.
  • You can use this to make long lines, like "-" * 10, to separate your work.
  • Just remember: to see the result on your screen, you still need to put everything inside a 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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • We use square brackets [ ] with a number to pick one letter or one item.
  • Counting starts at 0, so [0] means the first one.
  • The first item in your list is always number 0, the second is number 1, and the third is number 2.
  • For a string the first character in your list is always number 0, the second is number 1, and the third is number 2.
  • This works for both words, strings, or lists.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • Slicing is like using a pair of scissors to cut out just the part of a word or list you want to keep.
  • Inside the square brackets [ ], we use two numbers with a colon in the middle to show where to start and stop.
  • Python starts counting from 0, so the first number tells Python which character or item to start with.
  • The second number tells Python where to stop, but it doesn't include that last item—it stops right before it.
  • You can use this to grab the middle of a word like "eat" out of "Weather" or to pick just two colors out of a long list.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • You can use a special trick with square brackets [::-1] to flip things backward.
  • When you use this trick on a word like "stop," Python turns it into "pots."
  • It works just like a mirror! It takes the last letter and moves it to the very front.
  • This trick doesn't just work for words; you can also use it to flip a whole list of games or fruits.
  • Just remember to include both colons and the minus one -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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • [:-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.
  • This is called slicing, which means showing only part of a word or list.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • Python can change how words look.
  • .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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The .strip() helper is like a vacuum cleaner that sucks up extra spaces from the start and end of your words.
  • If you want to remove something else, like stars * or dashes -, you just put them inside the parentheses.
  • It’s perfect for tidying up your text so that only the important part in the middle is left!

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • .find() tells us where a word or letter starts (it gives a number).
  • Counting starts at 0, so 0 means the first spot.
  • .count() tells us how many times something appears.
  • These work with words (strings) and with lists.

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The .replace() helper works like a magic wand that swaps one piece of text for another.
  • Inside the parentheses, you first tell Python the "old" word you want to find, then the "new" word you want to put in its place.
  • It is a fast way to fix mistakes or change the whole meaning of a sentence, like turning "I like cats" into "I like dogs" in one step!

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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • .split() breaks a sentence into smaller parts.
  • By default, it splits at spaces.
  • You can tell it to split at other characters like - 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:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The .join() helper acts like glue to stick different parts together into one long string.
  • The symbol you put in quotes at the start, like a dash "-" or a star "*", is the "glue" that goes between each part.
  • You can use it to put dots between letters, like turning SOS into S.O.S.
  • It also works great for lists; you can take separate words like "Red" and "Blue" and join them into one line.
  • Just remember: the "glue" comes first, then the .join(), and then the things you want to stick together inside the parentheses.
Lesson Progress: 0%
Lesson Incomplete
← Previous: Lists
Lesson 6 of 16
Next: String Formatting →