👋 Work With Me

I help startups and teams build production-ready apps with Django, Flask, and FastAPI.

Let’s Talk →

I'm always excited to take on new projects and collaborate with innovative minds.

Address

No 7 Street E, Federal Low-cost Housing Estate, Kuje, Abuja 903101, Federal Capital Territory

Social Links

Tutorials

Python Tutorial Series – Lesson 4: Strings in Python

Python Tutorial for Beginners (Lesson 4): Learn strings in Python with examples, screenshots, and exercises – string operations, methods, and formatting explained.

Python Tutorial Series – Lesson 4: Strings in Python

Welcome back to the Python Tutorial Series for Beginners! 🎉

In Lesson 3, we explored operators in Python and saw how they help us perform calculations, comparisons, and logic.

Now in Lesson 4, we’re moving into one of the most fun and important parts of Python programming: Strings.

By the end of this lesson, you’ll understand:

  • What strings are and how to create them
  • Common string operations (concatenation, repetition, indexing, slicing)
  • Useful built-in string methods
  • String formatting techniques

🔹 What is a String?

A string is simply a sequence of characters enclosed in quotes.

 
# Examples of strings
name = "Python"
language = 'Programming'
sentence = """This is a multi-line string."""
  • Strings can be enclosed in single quotes ', double quotes ", or triple quotes ''' / """.
  • Triple quotes allow multi-line strings.

🔹 1. String Concatenation (Joining Strings)

You can join strings together using the + operator.

 
first_name = "John"
last_name = "Doe"
full_name = first_name + " " + last_name
print(full_name)   # Output: John Doe

 


🔹 2. String Repetition

You can repeat strings using the * operator.

 
word = "Hi! "
print(word * 3)   # Output: Hi! Hi! Hi!

🔹 3. String Indexing & Slicing

Strings are like arrays of characters. You can access individual characters or parts of the string.

 
text = "Python"

print(text[0])    # First character → 'P'
print(text[-1])   # Last character → 'n'
print(text[0:4])  # Slice from index 0 to 3 → 'Pyth'
print(text[2:])   # From index 2 to end → 'thon'

🔹 4. Useful String Methods

Python has many built-in methods for working with strings.

 
message = " hello world "

print(message.upper())     # HELLO WORLD
print(message.lower())     # hello world
print(message.title())     # Hello World
print(message.strip())     # Removes spaces → "hello world"
print(message.replace("world", "Python"))  # hello Python
print("Python" in message)  # Check if "Python" exists → False

🔹 5. String Formatting

Sometimes, you want to insert variables into strings.

f-strings (modern way):

 
name = "Alice"
age = 25

print(f"My name is {name} and I am {age} years old.")

.format() method (older way):

 
print("My name is {} and I am {} years old.".format(name, age))

🔹 Exercises for Beginners

Try these in a new file (lesson4.py):

  1. Create a string variable with your name. Print the first and last character.
  2. Join two strings: "Hello" and "World".
  3. Write a string "Python is fun!" and:
    • Convert it to uppercase
    • Replace "fun" with "awesome"
  4. Use slicing to extract "thon" from "Python".
  5. Challenge: Write a program that asks for a user’s name and age, then prints:
    • "Hello [name], you are [age] years old!" using f-strings.

🎯 Recap

In this lesson, you learned:
✅ Strings are sequences of characters in quotes
✅ You can join, repeat, index, and slice strings
✅ Python provides powerful string methods
✅ You can format strings with variables easily

Next up: Lesson 5 – Lists in Python (working with collections of data, list methods, indexing, and slicing). 📚

💼 Need a Developer?

I'm Kingsley Odume, a Django, Flask, and FastAPI developer with experience building SaaS platforms, APIs, and modern web apps. If you're a recruiter or business owner looking for a reliable software developer, let's connect!

🚀 Hire Me

Python, Python tutorials, Python Beginners series, Python Step-byStep
3 min read
Aug 20, 2025
By Kingsley Odume
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Aug 29, 2025 • 3 min read
Step-by-Step: Building a SaaS App with Django + Stripe Payments

Learn how to build a real-world SaaS app with Django and Stripe paymen...

Aug 21, 2025 • 3 min read
Final Wrap-Up: Python Tutorial Series for Beginners

Congratulations on completing the Python Tutorial Series! 🚀 In this w...

Aug 20, 2025 • 4 min read
Final Lesson: Mini Project – Putting It All Together in Python

In this final lesson, we’ll bring all those concepts together in a Min...

Your experience on this site will be improved by allowing cookies. Cookie Policy