1.3.1 Comments
Video
1.3.1 Comments
The video below describes ways that you can use pseudocode and comments to write complex python programs more easily.
What are Comments and Pseudocode?
Pseudocode helps programmers plan out what they are going to type without having to worry about all the specifics. It's sort of like an outline of a paragraph or essay. Pseudocode is great because you can focus on the ideas and the steps involved (the algorithm).
Comments are useful tools for transferring your pseudocode into a working python program without disrupting it. A comment, as shown in the video, allows a programmer to put notes (usually in English or another natural language) into their code. These notes are great for helping you plan out where in your program you want to do certain things, for remembering later what you were thinking, or for helping another programmer understand how your code works.
Try It Yourself
In Python, you can create comments in two ways:
-
Single-line comments - Start with a
#(hashtag/pound symbol):# This is a comment - Python will ignore this line print("This code will run") -
Multi-line comments - Use triple quotes
"""or''':""" This is a multi-line comment. You can write multiple lines here. Python will ignore all of this. """
Start with this example in the editor below to see how comments work:
Steps to follow:
- Look at the code in the editor - notice the comments that plan out the program
- Click Run to see what happens (the comments are ignored!)
- Try adding your own comments to plan out your slime shopping program
Note: The video shows creating a file in Spyder, but you're using the browser editor. Just type your code directly in the editor below!
Loading Python environment...