Python Syntax ও Indentation
🐍 Python Syntax ও Indentation (বিস্তারিত গাইড)
Python শেখার শুরুতেই সবচেয়ে গুরুত্বপূর্ণ দুটি বিষয় হলো Syntax এবং Indentation। Python-এর কোড স্ট্রাকচার অন্য ভাষার তুলনায় অনেক সহজ, কিন্তু এখানে indentation ঠিক না হলে কোড কাজ করবে না।
📌 ১. Python Syntax কী?
Syntax মানে হলো – Python কোড লেখার নিয়ম। Python এমনভাবে ডিজাইন করা হয়েছে যাতে কোড সহজে পড়া ও বোঝা যায়।
Python Syntax এর কিছু বৈশিষ্ট্য:
- Semicolon (
;) ব্যবহার করতে হয় না - Curly brace (
{ }) ব্যবহার হয় না - Line শেষে colon (
:) ব্যবহার হয় - Readable এবং clean code structure
✅ Example: Simple Python Syntax
print("Hello, Python World!")
# Output: Hello, Python World!
📌 ২. Python Indentation কী?
Indentation মানে হলো – লাইনের শুরুতে স্পেস দেওয়া। Python-এ indentation শুধু style না, এটি কোডের অংশ।
অন্য ভাষায় যেখানে { } ব্যবহার করা হয়,
Python সেখানে indentation ব্যবহার করে।
✅ Example: Indentation with if statement
age = 20
if age >= 18:
print("You are eligible to vote")
# Output: You are eligible to vote
📌 ৩. Indentation ভুল হলে কী হয়?
Indentation ভুল হলে Python সঙ্গে সঙ্গে error দেখায়। একে বলা হয় IndentationError।
❌ Wrong Indentation Example
age = 20
if age >= 18:
print("You are eligible")
# Output: IndentationError: expected an indented block
📌 ৪. কতটা Indentation ব্যবহার করবেন?
Python-এ সাধারণত প্রতি block এর জন্য 4 spaces ব্যবহার করা হয়।
- Tab ব্যবহার না করে space ব্যবহার করা ভালো
- সব জায়গায় একই ধরনের indentation ব্যবহার করুন
- Editor auto-indent feature ব্যবহার করুন
✅ Example: Indentation with loop
for i in range(3):
print(i)
# Output:
# 0
# 1
# 2
✨ সংক্ষেপে মনে রাখুন
- Python-এ Syntax খুব সহজ ও readable
- Indentation Python-এর core concept
- ভুল indentation = Error
- সবসময় 4 spaces ব্যবহার করুন
- Clean indentation = Clean code
✅ টিপস: Python শেখার সময় indentation ঠিক রাখতে পারলে, আপনি সহজেই advanced লেভেলে যেতে পারবেন।
লোড হচ্ছে...
1. Python এ Indentation কেন গুরুত্বপূর্ণ?
Python এ Indentation কোড ব্লক নির্ধারণ করে। ভুল Indentation হলে কোড Error দেয়।
2. Python Syntax এর একটি বিশেষ বৈশিষ্ট্য কী?
Python এ কোড ব্লক নির্ধারণের জন্য {} ব্যবহার করা হয় না, বরং Indentation ব্যবহার করা হয়।