Python Data Structures

Lists are one of the most commonly used data structures in Python. A list is an ordered collection of elements, which can be of any type, such as integers, floats, strings, or other objects. Lists are created using square brackets [] and elements are separated by commas.

# Creating a list of integers
my_list = [1, 2, 3, 4, 5]

# Creating a list of strings
my_strings = ["apple", "banana", "cherry"]

Lists are mutable, which means their elements can be changed. Elements can be accessed using their index, starting from 0 for the first element.

# Accessing elements of a list
print(my_list[0])  # Output: 1
print(my_strings[2])  # Output: "cherry"

# Modifying elements of a list
my_list[0] = 0
print(my_list)  # Output: [0, 2, 3, 4, 5]

Lists are often used for data processing tasks such as sorting, filtering, and aggregation.

Python overview :https://learndataengineeringskills.com/python/

 

Leave a Comment