Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Comments | The basics
Learn Python from Scratch

book
Comments

Before moving further, quick thing to learn: comments. Comment is a part of code which is not executed (ignored by the program). Comments are used as notes that developers leave for themselves or other users.

In Python there are single-line comments and multi-line comments (used less often).

Single-line comment start with symbol #. If placed at the beggining of the line entire line is ignored.

# this is a comment that I left as a note for myself
print("Hello, World!")
12
# this is a comment that I left as a note for myself print("Hello, World!")
copy

Comments can be placed at any position of any line. Anything before # sign will be executed, anything after # sign will be ignored.

print("Hello, world!") # Comments can be very helpful
1
print("Hello, world!") # Comments can be very helpful
copy

You can switch certain lines of code off by just placing a # sign (turning it into a comment).

# print("Hello, Mary!")
print("Hello, Jane!")
12
# print("Hello, Mary!") print("Hello, Jane!")
copy
Tarefa

Swipe to start coding

Switch off second ling of code by turning it into a comment.

Solução

print("This line should be printed")
# print("This line should NOT be printed")
print("This line should be printed")

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

print("This line should be printed")
print("This line should NOT be printed")
print("This line should be printed")

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt