How to comment on python3

Asked

Viewed 4,406 times

2

I’m starting to learn programming, and I’ve already learned the basics of language c++, in this language there is the function of commenting the programming that can be accessed by //, but the same does not work with the python3.

I wonder if you can comment on python3, and if so how to use it?

3 answers

4


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.

1

In Python comments are started with #, everything after the # will be ignored by the interpreter, so considered as comments, the closure of the comment ends when the line of the interpreter ends.

1

You can comment lines using #

# print("Isso não vai imprimir")

You can comment blocks using '''

'''
print("Esse bloco não vai executar")

'''

Browser other questions tagged

You are not signed in. Login or sign up in order to post.