🧩 Python Syntax β€” The Building Blocks of Python

What is Python Syntax? πŸ€”

Python syntax refers to the set of rules that define how a Python program is written and formatted. Unlike many languages, Python focuses onreadability and simplicity, making it one of the easiest languages to learn.

Note

πŸ’‘ Python uses indentation, not braces, to define code blocks.

1. Python Print Statement πŸ–¨οΈ

The print() function is used to display output.

print_example.py

print("Hello, World!")

2. Indentation in Python (Very Important) ⚠️

Python uses spaces (not curly braces like C/Java) to indicate code blocks. Missing or incorrect indentation leads to errors.

indentation.py

if True:
    print("This is inside the block")
print("This is outside the block")

Note

πŸ”Ž Recommended: Use 4 spaces for indentation (default in VS Code).

3. Comments in Python πŸ“

Comments help explain your code. Python supports single-line and multi-line comments.

Single-Line Comment

single_comment.py

# This is a comment
print("Python Syntax")

Multi-Line Comment

multi_comment.py

"""
This is a multi-line comment.
Useful for documentation.
"""
print("Learning Python!")

4. Python Variables ✨

Variables are created when you assign a value. Unlike many languages, Python does NOT require declaring types.

variables.py

name = "Sathish"
age = 25
height = 5.8
is_active = True

print(name, age, height, is_active)

5. Keywords in Python πŸ”‘

Python reserves certain words that cannot be used as variable names.

KeywordUsage
ifConditional statements
elseAlternative branch
forLooping construct
whileLooping condition
defDefine a function
classDefine a class
returnReturn a value

Note

πŸ’‘ Learn all keywords: Python Keywords List

6. Input From User ⌨️

Use input() to get data from the user.

input.py

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

7. Basic Data Types 🧠

Python supports many built-in data types.

TypeExampleDescription
str"hello"String (text)
int25Integer
float3.14Decimal number
boolTrue / FalseBoolean
list[1, 2, 3]Ordered collection
tuple(1, 2, 3)Immutable sequence
dict{"a": 1}Key-value pair

8. Operators in Python βž•βž–βœ–οΈβž—

Arithmetic Operators

arithmetic.py

a = 10
b = 3

print(a + b)  # Addition
print(a - b)  # Subtraction
print(a * b)  # Multiplication
print(a / b)  # Division
print(a % b)  # Modulus
print(a ** b) # Power

Comparison Operators

comparison.py

x = 5
y = 10

print(x == y)
print(x != y)
print(x > y)
print(x < y)

Logical Operators

logical.py

is_admin = True
is_active = False

print(is_admin and is_active)
print(is_admin or is_active)
print(not is_admin)

9. Conditional Statements 🧭

condition.py

age = 20

if age >= 18:
    print("Adult")
else:
    print("Minor")

10. Loops in Python πŸ”

For Loop

for_loop.py

for i in range(5):
    print(i)

While Loop

while_loop.py

count = 1
while count <= 5:
    print(count)
    count += 1

11. Functions in Python 🧩

Functions help organize reusable logic.

function.py

def greet(name):
    print("Hello,", name)

greet("Sathish")

Conclusion πŸŽ‰

Great job! You've learned the fundamental syntax rules of Python. Understanding these basics will help you write clean, readable, and professional-grade Python code.

>>β€œSyntax is the foundation of clarity β€” master it, and everything else becomes easier.” ✨

Want a tutorial on the next topic? Just tell me! 😊