Aan de slagGa gratis aan de slag

Methods

There will be times when you need to add values into a list, or update values in a dictionary. Here we will see some of the object-oriented nature of Python, which is different from R.

Everything in Python is an object (e.g., list object, dictionary object, etc). Objects can all perform certain tasks (e.g., add values to a list, update values in a dictionary). Instead of calling functions on the object you want to manipulate, you use dot notation to have the object perform an action on itself by calling a method.

Deze oefening maakt deel uit van de cursus

Python for R Users

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Append values to a list
person_list.____(____)

# Print person_list
print(person_list)

# Print the last element of person_list
print(____)
Code bewerken en uitvoeren