To write a comment in Python, just put a #
before the text that will be the comment:
# Isto é um comentário
The Python interpreter will ignore everything after the #
until the end of the line.
You can also insert them in a line that has code, after the code separated by two spaces (as recommended by PEP8):
print ('Olá, mundo!') # Este texto não será considerado
When you run the above code, you will see only the output 'Olá, mundo!'
, the remainder will be ignored by the interpreter.
To comment multiple lines, you can do so:
"""
Este é um
comentário
de várias
linhas
"""
Multi-line comments are often used to write "docstrings", as can also be seen in the PEP8.