Foundations of Python

You are currently auditing this course.
68 / 134

Comments

For long programs, you would prefer to add comments to your code so that you or anyone can understand the purpose of what you have coded because, it is often difficult to look at a piece of code and figure out what it is doing, or why.

For this reason, it is a good idea to add notes to your programs to explain in natural language what the program is doing. These notes are called comments, and in Python, you write it with the # symbol:

#Caclulating and printing my age
current_year = 2018
year_of_birth = 1990
age = current_year - year_of_birth
print(age)

It prints the age i.e. 28.

Everything from the # to the end of the line is ignored. It has no effect on the program.

Good variable names can reduce the need for comments, but long names can make complex expressions hard to read, so there is a trade-off.

As long as you follow the simple rules of variable naming, and avoid reserved words, you have a lot of choices when you name your variables.


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...