FRI · 09 OCT 2026 · 23:30 BST
O
OpenPress V 1.01
Breaking
Python Basics · Part 4 of 5 Beginner · 3 min read
Part 4 of 5 · 80% through this series
04

Python Syntax

Python Syntax Made Easy: Rules and Examples

If you are learning Python, the first thing you need to understand is its “syntax.” In programming, syntax is like grammar—it is the set of rules that defines how a Python program should be written and interpreted.

The best part about Python is that its syntax is designed to be highly readable, often looking like plain English! Let’s look at the key rules of Python syntax with easy-to-understand examples.

Python Indentation (The Most Important Rule!)

In most programming languages, you use curly brackets {} to group blocks of code. Python is different. Python uses indentation (spaces or tabs at the beginning of a line) to define code blocks. If your indentation is wrong, Python will throw an error.

Standard practice is to use 4 spaces for indentation.

# Correct Indentation
age = 20

if age >= 18:
    print("You are an adult.")
    print("You can vote!")

Output:

You are an adult.
You can vote!

Notice how the two print statements are pushed to the right? That tells Python they belong to the if statement. If you don’t indent them, Python will crash.

No Semicolons Needed

Unlike C, C++, or JavaScript, you do not need to put a semicolon ; at the end of every line. Python reads one line at a time. A new line simply means a new statement.

print("Hello")
print("World")

Output:

Hello
World

Variables Don’t Need Declarations

In Python, you don’t need to declare a variable type (like int or string) before using it. You just create a variable by assigning a value to a name using the equals sign =. Python figures out the data type automatically.

# Creating variables
name = "Alice"   # This is a string
age = 25         # This is an integer
height = 5.5     # This is a float (decimal)

print(name, "is", age, "years old.")

Output:

Alice is 25 years old.

Python is Case-Sensitive

Python treats uppercase and lowercase letters as completely different. This means Name, name, and NAME are three entirely different variables. You must be consistent!

language = "Python"
print(Language) 

Output:

NameError: name ‘Language’ is not defined

(Because we used a capital ‘L’ in the print statement, Python thought we were looking for a different variable!)

Writing Comments

Comments are notes left in the code for human readers. Python completely ignores them when running the program. To write a comment, use the hashtag symbol #. Anything after the # on that line becomes a comment.

# This is a full-line comment
print("Hello, World!") # This is an inline comment

# print("This line won't run because it is commented out")

Output:

Hello, World!

Using Quotes for Text

When you want to print text (also known as strings) or assign text to a variable, you must wrap it in quotes. Python allows you to use either single quotes ' ' or double quotes " ". They do the exact same thing, but you must close the quote with the same one you opened with.

message1 = "I am learning Python."
message2 = 'It is very fun!'

print(message1)
print(message2)

Output:

I am learning Python.
It is very fun!

Python’s syntax is exactly what makes it the perfect language for beginners. By remembering to use indentation, watching your capitalization, and using quotes for text, you are well on your way to mastering Python. Try writing a few of these examples yourself to see how natural Python feels!

Please log in to leave a comment.