Python Syntax और Basic Structure
Chapter 3: Python Syntax और Basic Structure हिंदी में विस्तार से उदाहरणों और Placeholder Images के साथ। अंत में 20 MCQs और Quiz दिए गए हैं।
📘 Chapter 3: Python Syntax और Basic Structure (Python का वाक्य-विन्यास और मूल संरचना)
🔰 इस Chapter में आप जानेंगे:
- Python Syntax कैसा होता है
- Python Code Structure (Indentation, Comments आदि)
- Statement और Blocks कैसे काम करते हैं
- Variables कैसे बनाए जाते हैं
- Input/Output कैसे किया जाता है
🧾 Python Syntax क्या है?
Python का Syntax सरल और पढ़ने में आसान है। इसका वाक्य-विन्यास अन्य Programming Languages की तुलना में कम जटिल है।
Python Code का सबसे महत्वपूर्ण हिस्सा है – Indentation।
[Add Image Here – Python syntax structure diagram]
🧱 Python Code Structure की मूल बातें
✅ 1. Indentation (जगह छोड़ना)
Python में Block बनाना Indentation पर निर्भर करता है। कोई भी Function, Loop या Condition सही तरीके से चलाने के लिए Line के शुरुआत में Spaces जरूरी होते हैं।
उदाहरण:
if 5 > 2:
print("5 बड़ा है 2 से")
❌ अगर आप Indentation नहीं देंगे तो Error आएगा।
✅ 2. Comments (टिप्पणियाँ)
Comments को Code में Notes की तरह लिखा जाता है, जो Execution में नहीं आते।
- Single-line comment:
#
से शुरू होता है - Multi-line comment:
''' ... '''
या""" ... """
# यह एक Comment है
print("Hello") # यह भी Comment है
✅ 3. Variables (चर)
Python में Variables को Declare करते समय Type बताने की ज़रूरत नहीं होती।
x = 5
name = "Amit"
Python एक Dynamically Typed Language है।
✅ 4. Statements (वाक्य)
Python में हर एक Line एक Statement होती है। Multiple statements एक ही लाइन में ;
से भी लिखे जा सकते हैं:
x = 10; y = 20; print(x + y)
✅ 5. Case Sensitivity
Python में Variable और Keywords Case-Sensitive होते हैं:
name = "Amit"
Name = "Raj"
print(name) # Output: Amit
print(Name) # Output: Raj
📥 Input और 📤 Output
✅ Output – print()
का उपयोग:
print("Welcome to Python")
✅ Input – input()
का उपयोग:
name = input("अपना नाम दर्ज करें: ")
print("नमस्ते", name)
[Add Image Here – Input/output terminal example]
🔄 Multiline Statement
Python में लंबी Statements को \
का प्रयोग करके अगली Line में ले जा सकते हैं:
total = 1 + 2 + 3 + \
4 + 5 + 6
🧠 निष्कर्ष
- Python का Syntax English के समान और सीधा है
- Code Structure को Indentation से नियंत्रित किया जाता है
- Variables को बिना Data Type बताए Declare किया जा सकता है
- Input/Output आसान तरीके से किया जा सकता है