Python Syntax

1. What is Python Syntax?

Syntax means the rules of writing Python code.

If you follow the rules, Python understands you.
If you break the rules, Python shows an error.

Good news 😊
Python syntax is simple and clean.

2. Python Uses Indentation (Spaces)

Python does not use { } like other languages.
It uses spaces (indentation) to group code.

βœ… Correct Example

if 10 > 5:
print("10 is greater than 5")

Here:

  • : means a new block starts

  • The space before print is very important

❌ Wrong Example

if 10 > 5:
print("10 is greater than 5")

This gives an IndentationError.

πŸ‘‰ Always use 4 spaces.

3. Python is Case-Sensitive

Capital letters and small letters are different.

Example

name = "Ravi"
Name = "Amit"
print(name)
print(Name)

Both are different variables.

4. Writing Python Statements

Usually, one line = one statement.

Example

print("Hello")
print("Python")

Python does not need ;

5. Python Comments

Comments are notes for humans.
Python ignores comments.

Single-Line Comment

# This prints a message
print("Hello Python")

Multi-Line Comment

"""
This program shows
Python syntax
"""

print("Welcome")

6. Python Variables Syntax

Variables store values.

Example

age = 25
name = "Suman"
price = 99.50

Python automatically understands the data type.

7. Variable Naming Rules

βœ” Start with a letter or _
βœ” Can use letters, numbers, _
❌ Cannot start with number
❌ Cannot use keywords

Correct Names

student_name = "Anil"
_age = 20
marks1 = 450

Wrong Names

1name = "Error"
class = 10
total-marks = 80

8. Multiple Statements in One Line

You can write multiple statements, but it’s not recommended.

Example

x = 5; y = 10; print(x + y)

πŸ‘‰ Better to write in separate lines.

9. Python Line Continuation

Long lines can be broken using \.

Example

total = 10 + 20 + \
30 + 40
print(total)

10. Python Code Blocks

A code block is a group of lines with the same indentation.

Example

if 5 > 2:
print("Yes")
print("Five is bigger")

Both print lines are inside the if block.

11. Common Syntax Errors (Beginner)

❌ Missing indentation
❌ Wrong spelling (pritn)
❌ Missing quotes
❌ Using keyword as variable

Example Error

print(Hello)

Correct:

print("Hello")

12. Simple Practice Examples

Example 1: Print Message

print("Learning Python is easy")

Example 2: Check a Number

number = 10

if number > 5:
print(“Number is greater than 5”)

Example 3: User Input

name = input("Enter your name: ")
print("Welcome", name)

13. Summary (Python Syntax)

βœ” Python uses spaces, not { }
βœ” Indentation is very important
βœ” Python is case-sensitive
βœ” Comments help humans
βœ” Code should be clean and readable

πŸ“˜ Perfect for Beginners & eBook

This chapter is ideal for:

  • Python beginner eBooks

  • School / college students

  • Self-learners

If you want next, I can write:

  • Python Variables & Data Types

  • if–else syntax (easy)

  • Loops (for, while)

  • Practice questions with answers

  • Bangla + English version

Just tell me 😊

You may also like...