Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

lists-tuples

Lists and tuples

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Lists and tuples: the syntax, patterns, and safety habits you need before advancing in Python.

Lists and dicts are the core data model—know copying, hashing, and when to use sets.

You will apply Lists and tuples in contexts like: Scripts, Django/FastAPI apps, notebooks, and glue code between systems.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Lists are ordered, mutable sequences—Python's workhorse like JavaScript arrays. Tuples are ordered and immutable—useful for fixed records and dict keys.

List basics

nums = [1, 2, 3]
nums.append(4)
nums[0] = 10
print(len(nums), nums[-1])

Tuples

point = (3, 4)
x, y = point  # unpacking
# point[0] = 5  # TypeError: immutable

Parentheses are optional for tuples—a, b = 1, 2 creates a tuple. Single-element tuples need a trailing comma: (1,).

Important interview questions and answers

  1. Q: List vs tuple?
    A: Lists are mutable and use more memory; tuples are immutable, hashable (if elements are), and signal fixed structure.
  2. Q: How copy a list?
    A: list.copy(), nums[:], or copy.copy—assignment aliases the same list.

Self-check

  1. Which type can you append to?
  2. What does negative index -1 mean?

Tip: Use tuples for fixed records (coordinates, DB rows); lists when you need append/pop mutability.

Interview prep

List vs tuple?

Lists mutable; tuples immutable—tuples can be dict keys when elements are hashable.

Copy a list?

.copy(), slice [:], or list()—assignment aliases the same object.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • List vs tuple?
  • append O(1)?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump