Python Syntax

🧩 Python Syntax

Python syntax refers to the rules that define how Python code must be written and formatted. Python emphasizes readability and uses indentation instead of braces {} like other languages.


✅ 1. Python Code Execution

Python code is executed line by line (interpreted language).

Example:

print("Hello, Python!")

✅ 2. Indentation (Very Important)

Python uses indentation (spaces or tabs) to define blocks of code—NOT curly braces.

Example:

if 5 > 2:
print("Five is greater than two!")

🚫 Wrong syntax (no indentation):

if 5 > 2:
print("Five is greater than two!")

✅ 3. Comments

Comments help explain code and are ignored by Python.

➤ Single-line comment:

# This is a comment
print("Hello")

➤ Multi-line comment:

"""
This is a multi-line comment
used for documentation
"""


✅ 4. Variables and Assignment

You don’t need to declare variable types.

name = "Vipul"
age = 25

✅ 5. Case Sensitivity

Python is case-sensitive.

x = 10
X = 5
print(x) # Output: 10
print(X) # Output: 5


✅ 6. Print Statement

Used to display output.

print("I am learning Python")

✅ 7. Multiple Statements on One Line (Not Recommended)

a = 10; b = 20; print(a + b)

✅ 8. Line Continuation

You can break long lines using \:

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

✅ 9. Using Quotes

Python allows:

'Hello'
"Hello"
"""Hello"""

Triple quotes allow multi-line strings.


Quick Syntax Example

# Python syntax demonstration
x = 10
if x > 5:
print(“x is greater than 5”)


🎯 Summary

Concept Python Rule
Blocks of code Defined by indentation
Comments # or """ """
Case-sensitive Yes
End of line No semicolon needed
Printing print()

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *