List


Collection Type Ordered Mutable Duplicate Elements Indexing Example
List Yes Yes Yes Yes [1, 2, 3]


A list is a collection that is ordered and changeable. It allows to duplicate members.

It is the most used collection in Python.

# To create (instantiate)
a = [2,beam_12,42.1234,True,True,False]

# To retrieve an element
b = a[2]  # 42.1234

# To remove an element
a.remove(beam_12)
a.pop(2)

# To insert an element
a.append(stud_01)


🦊 One major advantage of a list in Python is its flexibility. Lists are mutable, meaning you can modify their content by adding, removing, or changing elements. They can also hold different types of data in the same list, including numbers, strings, and even other lists or objects. This makes lists a versatile tool for storing and manipulating collections of data in Python. Additionally, lists in Python are ordered, meaning the order in which elements are added to the list is preserved, which can be important in many programming scenarios.: 🦊


🛠 Exercise


🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

Solution:

🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍