Python Quick Guide - Step 1: Basic Syntax and Data Types (1) - Comments, Screen Output
Series - Python Quick Guide
Contents
Info
- This course is designed to help you learn the basics of Python programming as quickly as possible through hands-on practice.
- The “Style Guide” sections primarily cover guidelines from PEP8 for writing clean Python code.
- You can run and see the results of each code example.
Feel free to experiment with the code - reloading the page will reset the content.
Step 1: Basic Syntax and Data Types
1.1. Comments
- Lines beginning with a hash symbol (
#
) are interpreted as comments. - Comment lines do not affect the execution of the program but are used to explain how the program works.
- Everything from the hash symbol to the end of the line is considered a comment.
Style Guide
- After the
#
, add 1 space before beginning your comment text. - When adding a comment after a code statement, include at least 2 spaces between the code and the comment.
1.2. Screen Output
- To display data on the screen, use the
print
function. - Strings are enclosed in double quotes (
"
) or single quotes ('
).
- By default, the print function inserts a newline at the end.
- If you don’t want to include a newline, specify an empty string (
''
) for theend
parameter.
📚 Exercise
Output the string “Hello, World!” in a single line by using two print statements - one for “Hello,” and one for " World!".