1.2.1 Scripts

Until now we have learned that we can interact with Python using the CLI interface. But entering Python code at the >>> prompt is slow and can only be done one line at a time. It is also not possible to save the code so that another person can run it. Thankfully, there is an even better way to enter Python code.

Python code can be entered using a script. A script is a series of lines of Python code that will be executed all at once.

In Thonny you can write a series of commands in the editor window and save them as a script.

scripts


To create a simple script copy the following code to the script area and save it as my_first_script.

Press the play button to view the results of the script.