Mark As Completed Discussion

Python Data Structures

Python provides built-in data structures that are essential for storing and manipulating data. The three fundamental data structures in Python are lists, dictionaries, and tuples.

Lists

A list is a collection of items that are ordered and changeable. It allows duplicate items and is represented by square brackets ([]). You can access and modify elements in a list using indexing and slicing.

PYTHON
1import numpy as np
2
3# Create a list
4numbers = [1, 2, 3, 4, 5]
5
6# Access elements in the list
7print(numbers[0])  # Output: 1
8
9# Modify elements in the list
10numbers[2] = 9
11print(numbers)  # Output: [1, 2, 9, 4, 5]
12
13# Iterate over the list
14for number in numbers:
15    print(number)
PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment