Python Syntex

Python syntax can be executed by writing code directly in the Command Line: Or by creating a Python file (.py) and running it: Python Indentation Indentation refers to the spaces at the beginning of a code line. Unlike many other programming languages, indentation in Python is required and is used to define a block of […]

1 min read Lesson 37 of 43 86% through track

Python syntax can be executed by writing code directly in the Command Line:

>>> print("Hello, World!")
Hello, World!

Or by creating a Python file (.py) and running it:

C:\Users\YourName> python myfile.py

Python Indentation

Indentation refers to the spaces at the beginning of a code line.

Unlike many other programming languages, indentation in Python is required and is used to define a block of code.

Example:

if 5 > 2:
    print("Five is greater than two")

Python will give an error if indentation is missing:

if 5 > 2:
print("Five is greater than two")

The standard indentation is 4 spaces.

if 5 > 2:
    print("Hello")
    print("World")

Python uses indentation to make code clean, readable, and organized.