Python Documentation

Python Syntax

Python Syntax

Python syntax is designed to be clear and readable. Here are some key aspects of Python syntax:

Indentation

Python uses indentation to define code blocks. Typically, 4 spaces are used for indentation.

if x > 0:
print("x is positive")

Comments

Single-line comments start with #. Multi-line comments are enclosed in triple quotes.

# This is a single-line comment
"""
This is a
multi-line comment
"""

Variables

Variables are created when you assign a value to them. No need to declare types.

x = 5
y = "Hello"

Functions

Functions are defined using the 'def' keyword.

def greet(name):
return f"Hello, {name}!"