Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Collections · Lesson 15 of 25

    Tuples and sets

    Fixed sequences and collections of unique values.

    8 minutes2 games

    A tuple is an immutable sequence, useful for coordinates or multiple return values. A set holds unique values without a guaranteed order, useful for deduplication and membership. set() creates an empty set; {} creates an empty dictionary.

    Python
    point = (3, 7)
    x, y = point
    print(x, y)
    unique = set(["python", "css", "python"])
    print(sorted(unique))
    print("css" in unique)
    print(sorted({1, 2, 3} & {2, 3, 4}))
    ToolUse

    tuple

    Ordered; its elements cannot be reassigned

    set

    Unique values; no indexing

    a & b / a | b

    Intersection / union

    Important

    A one-item tuple needs a comma: (5,). A tuple can contain a mutable list; tuple immutability does not freeze nested objects.

    Interview question

    Why not expect a fixed order when printing a set?

    What's the output?

    print(len(set([1, 1, 2, 3, 3])))

    What will this code print?

    Exercise

    Remove duplicates and print the numbers as a sorted list.

    Expected output: [1, 2, 3]

    Python
    nums = [3, 1, 3, 2]
    

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousDictionariesNextComprehensions, enumerate and zip
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.