👋 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 6: Tuples in Python

Python Tutorial for Beginners (Lesson 6): Learn tuples in Python with examples, screenshots, and exercises – tuple creation, immutability, unpacking, and use cases explained.

Python Tutorial Series – Lesson 6: Tuples in Python

Welcome back to the Python Tutorial Series for Beginners! 🎉

In Lesson 5, we explored lists – how to create them, modify them, slice them, and use common methods.

Now in Lesson 6, we’re diving into tuples – another way of grouping data in Python.

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

  • What tuples are and how they differ from lists
  • How to create and use tuples
  • Accessing tuple elements
  • Tuple unpacking
  • When to use tuples vs lists
  • Practical beginner exercises

🔹 What is a Tuple?

A tuple is very similar to a list – it can store multiple items, even of different data types.

👉 The big difference: Tuples are immutable (you cannot change them once created).

 
# Examples of tuples

fruits = ("apple", "banana", "cherry")
numbers = (10, 20, 30, 40)
mixed = ("Python", 3.14, True, 42)
  • Tuples use parentheses ()
  • They can contain different data types
  • They are ordered and immutable

🔹 1. Accessing Tuple Elements

Just like lists, tuples are indexed (starting from 0).

 
fruits = ("apple", "banana", "cherry")

print(fruits[0])   # First item → apple
print(fruits[-1])  # Last item → cherry

🔹 2. Tuples are Immutable

Once you create a tuple, you cannot change its elements.

 
fruits = ("apple", "banana", "cherry")

# This will cause an error ❌
fruits[1] = "orange"

If you need to modify data, use a list instead.


🔹 3. Creating a Tuple with One Item

To create a tuple with just one item, you must include a trailing comma.

 
one_item = ("apple",)   # ✅ Correct
not_a_tuple = ("apple") # ❌ This is just a string
 

🔹 4. Tuple Unpacking

You can assign tuple elements directly into variables.

 
person = ("John", 25, "Developer")

name, age, job = person

print(name)  # John
print(age)   # 25
print(job)   # Developer

🔹 5. Using Tuples in Python

Why use tuples instead of lists?

  • Performance: Tuples use less memory and are faster
  • Data integrity: Tuples are read-only, so they’re safer for fixed collections
  • Hashable: Tuples can be used as keys in dictionaries, lists cannot

Example:

 
locations = {
   (6.5244, 3.3792): "Lagos",
   (51.5072, -0.1276): "London"
}

print(locations[(6.5244, 3.3792)])  # Lagos

🔹 Exercises for Beginners

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

  1. Create a tuple of your 3 favorite colors and print the second one.
  2. Try modifying an element in the tuple – what happens?
  3. Create a tuple with one element (be careful with the comma).
  4. Use tuple unpacking to assign values (“Python”, 3.10, “Cool”) to three variables.
  5. Challenge: Create a dictionary that uses tuples as keys (e.g., coordinates → city name).

🎯 Recap

In this lesson, you learned:
✅ Tuples are like lists but immutable
✅ You can access elements by index
✅ You can unpack tuples into variables
✅ Tuples are great for fixed collections and dictionary keys

Next up: Lesson 7 – Dictionaries in Python 🗂️ (key-value pairs you’ll use everywhere in coding).

💼 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