Skip to content
techsnow

Introduction

Syntax and Indentation

Python uses indentation (spaces at the start of a line) to group code. Other languages use curly braces { }; Python uses whitespace.

age = 20
if age >= 18:
    print("You can vote.")      # inside the if
    print("Don't forget your ID.")
print("This always runs.")      # outside the if
  • The standard is 4 spaces per level.
  • Every line in a block must use the same indentation.
  • A line ending with : starts a new block.

Comments

# This is a comment. Python ignores it.
price = 500  # comments can go at the end of a line

"""
This is a multi-line string,
often used as a multi-line comment.
"""