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
Here:
-
:means a new block starts -
The space before
printis very important
β Wrong Example
This gives an IndentationError.
π Always use 4 spaces.
3. Python is Case-Sensitive
Capital letters and small letters are different.
Example
Both are different variables.
4. Writing Python Statements
Usually, one line = one statement.
Example
Python does not need ;
5. Python Comments
Comments are notes for humans.
Python ignores comments.
Single-Line Comment
Multi-Line Comment
6. Python Variables Syntax
Variables store values.
Example
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
Wrong Names
8. Multiple Statements in One Line
You can write multiple statements, but itβs not recommended.
Example
π Better to write in separate lines.
9. Python Line Continuation
Long lines can be broken using \.
Example
10. Python Code Blocks
A code block is a group of lines with the same indentation.
Example
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
Correct:
12. Simple Practice Examples
Example 1: Print Message
Example 2: Check a Number
Example 3: User Input
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 π
