Creating and Accessing Lists
Build lists and access elements by index and slice.
Introduction
Lists are Python's most flexible ordered collection. They hold any mix of types and support indexing, slicing, and iteration.
Creating a List
my_list = [1, 2, 3] or empty = [] Lists are ordered and mutable. Elements can be of any type.
nums = [1, 2, 3]
mixed = [1, 'hi', True]
print(nums, mixed)All lessons in this course
- Creating and Accessing Lists
- Modifying Lists
- Tuples and Immutability
- Nested Lists and Iteration