Lists
Completion requirements
Different data types or objects can be listed in a so-called
With
list (also a sequential data type):person = ["Eick", "Wolfhard", 50, 1.84, ["Léon", "Stella", "Olivia"]]

person can be printed easely:
print(person) # output: ['Eick', 'Wolfhard', 50, 1.84, ['Léon', 'Stella', 'Olivia']]
List functions
Python offers some functions that are very helpful for processing lists:len() returns the length of the list.n = len(person) # output 5
With
append() another object can be appended to the end of the list.person.append("male") # person = ['Eick', 'Wolfhard', 50, 1.84, ['Léon', 'Stella', 'Olivia'], 'male']
removes the last object from the list and returns it.pop()
person.pop() # 'male'
# ['Eick', 'Wolfhard', 50, 1.84, ['Léon', 'Stella', 'Olivia']]
If pop() has a parameter, the object in the list is deleted and output at the position specified by the parameter.
person.pop(3) # 1.84
# person = ['Eick', 'Wolfhard', 50, ['Léon', 'Stella', 'Olivia']]
insert() inserts an object into the list at the position specified in the parameter.
person.insert(2,"Teacher Plus")
# person = ['Eick', 'Wolfhard', 'Teacher Plus', 50, ['Léon', 'Stella', 'Olivia']]
remove() removes a specific object from the list. The position of the object is irrelevant.
person.remove("Wolfhard")
# person = ['Eick', 'Teacher Plus', 50, ['Léon', 'Stella', 'Olivia']]
Last modified: Wednesday, 7 September 2022, 10:17 AM