Python Syntax
Python syntax is designed to be clear and readable. Here are some key aspects of Python syntax:
Python uses indentation to define code blocks. Typically, 4 spaces are used for indentation.
if x > 0:
ㅤprint("x is positive")
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 are created when you assign a value to them. No need to declare types.
x = 5
y = "Hello"
Functions are defined using the 'def' keyword.
def greet(name):
return f"Hello, {name}!"