Python Lists Explained | Python Bits | Kovolff

Опубликовано: 17 Март 2026
на канале: kovolff
36
1

A Python list is a series of elements. These elements can be of any type.

To access an element in a list, just call list name + index of the required element.
i.e. my_list[3]

You can also access a whole range of elements, just input start index and end index separated by a colon.
i.e. my_list[2:5] produces all elements from element 2 to element 4 (up to 5 but excluding 5),

Lists can be edited, aka are mutable. Existing elements can be given new values, or removed. New elements can be added. Whole lists can be appended to existing lists. Lists can be extended with other lists.

To remove elements from a list:
my_list.pop(2) removes element 2 from the list
my_list.remove(‘abc’) removes the first occurence of abc

To clear a list
my_list.clear produces an empty list

To create an empty list: new_list = []

Further list methods or functions
len(my_list) produces the number of elements found in the list
max(my_list) give out the biggest element in the list. All elements in the list must be of one type
min(my_list) outputs the smallest element. Again here all elements must be of one type.

Iterating through lists can take one of two forms:

For a in my_list:
print(a)

a is a placeholder for an element, and thus each element is printed


For i in range(len(my_list)):
print(my_list[i])

i is a placeholder for an element’s index, and thus each element is printed via its index.

#python #list #element