Comments are notes within your code that are ignored by the Python interpreter but are valuable for human readers. They help explain the code's logic, purpose, and any non-obvious details. While a machine executes the code, it is humans who must read and maintain it. Good commenting habits are essential for writing clean and understandable programs.
Let's start with a simple script without any comments. In the WebIDE, locate the file purpose.py in the file explorer on the left panel and open it.
Add the following code to the purpose.py file:
x = 10
y = 20
z = x + y
print(z)
Save the file by pressing Ctrl + S.
To run the script, open the integrated terminal in the WebIDE by navigating to the top menu and selecting Terminal -> New Terminal. The terminal will open at the bottom of the screen, and the default path is ~/project.
Execute the script by running the following command in the terminal:
python purpose.py
You will see the output of the calculation:
30
This script is straightforward, but in a larger program, it might not be immediately clear what x, y, and z represent. In the next step, we will add comments to make this code easier to understand.