Sign InNuggetsCoursesCodePadCheatsheet

Names in Python

Remember that everything in Python is an object? A name in Python can refer to any type of object, even a function, which is also an object.

In this example, the variable named what refers to four different types of objects at different instances - an integer (line 3), a list (line 4), a string (line 5), and then a function (line 6).

def add(x, y): print(x + y) what = 3 print(what) what = [1, 2] print(what) what = "1 + 2" print(what) what = add(3, 4)
© CS Wonders·Home·About·Contact·Classes·Gallery·Glossary·Fun Facts