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 13 of 25

    Lists

    A list of values: add, remove and loop.

    8 minutes3 games

    A list lives in [ ]. append adds to the end, remove deletes a value and len counts items. A powerful shortcut is the list comprehension: [n * 2 for n in nums].

    Python
    langs = ["Python", "JavaScript"]
    langs.append("C++")
    print(langs, len(langs))
    print(langs[0], langs[-1])
    
    nums = [3, 8, 1, 12]
    print(sorted(nums))
    print([n * 10 for n in nums])
    print([n for n in nums if n > 5])

    nums =

    3[0]
    8[1]
    1[2]
    12[3]

    Important

    b = a does not copy a list; both names refer to the same object. a.copy() is shallow, so nested objects may still be shared.

    Interview question

    How do sorted(nums) and nums.sort() differ?

    What's the output?

    a = [1, 2, 3]
    a.append(4)
    print(len(a))

    What will this code print?

    Complete the code

    Add "Go" to the end of the list.

    langs = ["Python"]
    langs.("Go")

    Exercise

    Print a list with every number squared.

    Expected output: [1, 4, 9, 16]

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

    Learn more from

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

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousParameters and scopeNextDictionaries
    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.