2. Python¶
Activity: CodeLens 2.1 (cl_l38_2a_en)
Usually, we want to repeat a series of commands several times
One way to do this is to use a function
Activity: CodeLens 2.2 (cl_l38_2b_en)
Don’t forget parentheses when calling the function!
If you forget the parentheses, Python will return the memory address where the function is defined.
Activity: CodeLens 2.3 (cl_l38_2c_en)
We can put parameters in a function
Activity: CodeLens 2.4 (cl_l38_2d_en)
Functions cease to exist as soon as you exit the Python interpreter
Hence, programs generally consist of modules, which are files stored on disk
A module is a text file containing a Python program
You can edit modules in a development environment, which highlights reserved words, performs automatic indentation, etc.
We save a program called
chaos.py
Don’t forget the
.py
extensionWe can run the program with the “Run” button.