HTML CSS JAVASCRIPT PYTHON JAVA

Python Syntax

Python syntax refers to the set of rules that define how Python code is written and interpreted. Python is designed to be simple and easy to read, which makes it a great choice for beginners.

Python Example

Below is a simple Python program that prints a message to the screen.

Example
print("Hello, Python!")
Try this code

Python Indentation

Indentation is very important in Python. It is used to define blocks of code. Unlike many other programming languages, Python uses indentation instead of curly braces.

Example
if 5 > 2:
    print("Five is greater than two")
Try this code

If indentation is incorrect, Python will give an error.

Python Variables

In Python, variables are created when you assign a value to them. You do not need to declare the type of a variable.

Example
x = 5
y = "John"
print(x)
print(y)
Try this code

Python Comments

Comments are used to explain the code. They are ignored by the Python interpreter.

Example
# This is a comment
print("Hello")
Try this code

Line Breaks

Python uses new lines to complete commands. Each statement is usually written on a new line.

Example
print("Hello")
print("World")
Try this code

Multiple Statements in One Line

You can also write multiple statements in one line using a semicolon (;), but it is not recommended.

Example
print("Hello"); print("World")
Try this code

Why Python Syntax is Important