—You’ve written a Python script or project with several modules
—You press Run, figuratively or literally
—What happens behind the scenes in the microseconds or seconds or minutes it takes for your program to run?
You can dive into the details about the internal functioning of Python to learn how a Python program works.
But...there’s another way to visualise what’s happening.
Each blank Python file you create is represented by a room that’s mostly empty except for a few shelves on one of the walls and a small booklet named “built-in”. This booklet has some functions, constants, and other keywords in it.
Monty is a friendly, hard-working character who represents the computer program. He’s very fast and efficient, but you’ll need to spell out instructions clearly when you ask him to do something.
When you ask Monty to create a variable to store some information in, he’ll get an empty box and label it with the variable name you tell him. He’ll place whatever data you want in the box and place the box on one of the shelves.
If you’ve used an import statement, Monty will leave the room briefly to go to the library, where he’ll fetch a book with the name of the module you’re importing. He’ll take this book back to the room and place it on a shelf.
When you use any name in your script, Monty will look around the room to find that name. It may be a book (a module you’ve imported), it may be a box (a variable you’ve created), or it may be a name that’s inside the “built-in” booklet.
A function is a mini-program and is represented by a separate room—the function room—adjacent to the main room.
The door leading from the main room to the function room has a label on it. The name on this label is the function name.
When you call a function in your program, Monty will find the name of the function on the function room’s door. He’ll open the door and go through it. He may need to take some things with him as he goes to the function room. These are the arguments in the function call.
Monty performs all the tasks he’s asked to do in the Function Room and then returns to the main room, possibly bringing some information along with him. These are the items of data returned by the function.
Want to read more? This is the analogy I've developed to help me understand what's really happening "behind the scenes" when a computer program runs. You can read the full analogy here: Understanding How a Python Program Works
—You press Run, figuratively or literally
—What happens behind the scenes in the microseconds or seconds or minutes it takes for your program to run?
You can dive into the details about the internal functioning of Python to learn how a Python program works.
But...there’s another way to visualise what’s happening.
Each blank Python file you create is represented by a room that’s mostly empty except for a few shelves on one of the walls and a small booklet named “built-in”. This booklet has some functions, constants, and other keywords in it.
Monty is a friendly, hard-working character who represents the computer program. He’s very fast and efficient, but you’ll need to spell out instructions clearly when you ask him to do something.
When you ask Monty to create a variable to store some information in, he’ll get an empty box and label it with the variable name you tell him. He’ll place whatever data you want in the box and place the box on one of the shelves.
If you’ve used an import statement, Monty will leave the room briefly to go to the library, where he’ll fetch a book with the name of the module you’re importing. He’ll take this book back to the room and place it on a shelf.
When you use any name in your script, Monty will look around the room to find that name. It may be a book (a module you’ve imported), it may be a box (a variable you’ve created), or it may be a name that’s inside the “built-in” booklet.
A function is a mini-program and is represented by a separate room—the function room—adjacent to the main room.
The door leading from the main room to the function room has a label on it. The name on this label is the function name.
When you call a function in your program, Monty will find the name of the function on the function room’s door. He’ll open the door and go through it. He may need to take some things with him as he goes to the function room. These are the arguments in the function call.
Monty performs all the tasks he’s asked to do in the Function Room and then returns to the main room, possibly bringing some information along with him. These are the items of data returned by the function.
Want to read more? This is the analogy I've developed to help me understand what's really happening "behind the scenes" when a computer program runs. You can read the full analogy here: Understanding How a Python Program Works