Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Comments | Getting Started
Introduction to Python Video Course
course content

Conteúdo do Curso

Introduction to Python Video Course

Introduction to Python Video Course

1. Getting Started
2. Variables and Types
3. Conditional Statements
4. Other Data Types
5. Loops
6. Functions

Comments

In Python, comments are lines of text in your code that the Python interpreter ignores. Comments are useful when you don't want a particular line or multiple lines of code to run.

As you will see throughout the course, comments are useful for giving instructions, documenting your code, and leaving notes for yourself and others.

To write a comment, simply put a # symbol at the beginning of any line of code. Let's see how this works in practice.

Now it's your turn to practice using comments. Your task is to comment out the items that do not belong with the categories mentioned for aisle 2.

1234567891011
# Aisle 2 in our grocery store contains Fruit, Vegetables, and Salad Dressing. # Your task is to comment out the items below that do not belong in Aisle 2. print("Fruit, Vegetables, and Salad Dressing are in Aisle 2") print("Strawberries") print("Cereal") print("Blueberries") print("Chicken") print("Ranch dressing") # Run the code after commenting out the unrelated items to see if you've done it right!
copy

You can also quickly comment out a line or multiple lines of code by first highlighting the code, then using a shortcut: on Windows, simultaneously press 'Ctrl + /', and on Mac, press 'Command + /'.

Try using the shortcut keys in the following exercise:

12345678910111213141516
# Aisle 3 in our grocery store contains Snacks, Chips, and Sodas. # Your task is to comment out the items below that do not belong in Aisle 3. # Remember to use the shortcut keys to quickly comment lines of code. print("Welcome to Aisle 3: Snacks, Chips, and Sodas") print("Potato Chips") print("Diet Coke") print("Tortilla Chips") print("Pretzels") print("Milk") print("Orange Juice") print("Whole Wheat Bread") print("Greek Yogurt") # Run the code after commenting out the unrelated items to see if you've done it right! # Use Ctrl + / on Windows or Command + / on Mac to toggle comments.
copy

What symbol is used to write a comment in Python?

Selecione a resposta correta

Tudo estava claro?

Seção 1. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt