SyntaxStudy
Sign Up
Python Beginner 8 min read

Lists Introduction

Python Lists

Lists are ordered, mutable sequences that can hold mixed types.

Creating Lists

fruits = ["apple", "banana", "cherry"]
mixed = [1, "hello", 3.14, True]
empty = []
nested = [[1,2], [3,4]]

Accessing Elements

print(fruits[0])    # apple
print(fruits[-1])   # cherry (last)
print(fruits[1:3])  # ['banana', 'cherry']

Modifying

fruits[1] = "blueberry"
fruits.append("mango")
fruits.insert(1, "kiwi")
fruits.remove("apple")
popped = fruits.pop()
Pro Tip

Use fruits[:] to create a shallow copy of a list.