Printing Output and Adding Comments
The print() function is how your program shows output. It is usually the first thing every Python programmer learns, and you will use it constantly. In this lesson you will also learn comments, the notes you leave in code for yourself and others.
What You'll Learn
- How to display text and numbers with
print() - Printing several items on one line
- Controlling spacing with
sepandend - Writing single-line and multi-line comments
Basic Print
Text goes inside quotes. Single quotes '...' and double quotes "..." both work, so pick whichever is convenient.
Printing Multiple Items
Separate items with commas and print() puts a space between them:
Notice 42 has no quotes. It is a number, not text, so it does not need them.
Exercises
The sep and end Parameters
sep controls what goes between items. end controls what goes after the line (the default is a new line):
Comments
A comment starts with #. Python ignores everything after it, so comments are notes for humans, not instructions for the computer.
Good comments explain why something is done, not restate the obvious. You can also "comment out" a line to disable it temporarily:
Key Takeaways
print()displays output; text goes inside quotes- Separate multiple items with commas (they print with a space between)
sepsets what goes between items;endsets what comes after#starts a comment, which Python ignores- Good comments explain why, and can temporarily disable code

