First Steps

Comments in Python

Learn about comments in Python and how to use them to structure and describe our code.


Let's talk about comments in your code.

A very important aspect of programming is documenting what you are doing.

In Python, you can add comments to your code to make it more understandable.

You can add a comment using the # symbol.

Python

Everything after the # symbol is ignored when we run our code.

The following code will throw an error because num is not really created:

Python
Output

What will be the output?

Python

You can even add comments at the end of an existing code line. This is called an inline comment:

Python

Using comments, we can structure our code and make it very clear what our program is doing. Here's an example:

Python