Python Keywords & Commands
A Complete Guide for Beginners
Author: ChatGPT (AI Guide)
Introduction
Python ke keywords reserved words hote hain jo syntax define karte hain. Ye keywords
programming ke rules set karte hain aur inka specific use hota hai.
1. Conditional Statements
Keywords: if, elif, else
- if: Condition check karta hai.
- elif: Extra condition check karne ke liye.
- else: Default case jab koi bhi condition true na ho.
Example:
if age > 18:
print('You can vote')
elif age == 18:
print('Just eligible')
else:
print('Cannot vote')
2. Loops
Keywords: for, while, break, continue, pass
- for: Loop ek sequence ke har element par chalta hai.
- while: Jab tak condition true hai, tab tak loop chalta hai.
- break: Loop ko turant stop karta hai.
- continue: Current iteration skip karke next pe chala jata hai.
- pass: Placeholder statement jo kuch nahi karta.
3. Functions
Keywords: def, return, lambda
- def: Function define karne ke liye.
- return: Function ka output return karta hai.
- lambda: Anonymous (nameless) function banata hai.
4. Lists & Arrays
Keywords: append, insert, remove, sort, pop, extend
- append(): List ke last me element add karta hai.
- insert(): Specific position pe element add karta hai.
- remove(): Kisi specific element ko delete karta hai.
- sort(): List ke elements ko sort karta hai.
- pop(): Last element remove karta hai.
- extend(): Ek list me doosri list ke elements add karta hai.
5. Exception Handling
Keywords: try, except, finally, raise
- try: Error hone wale code ko handle karta hai.
- except: Error aane par alternate code execute karta hai.
- finally: Hamesha execute hone wala block.
- raise: Custom error generate karta hai.
6. File Handling
Keywords: open, read, write, with
- open(): File ko open karta hai.
- read(): File ke content ko read karta hai.
- write(): File me naya content likhta hai.
- with: File ko safely handle karta hai.
7. Importing Modules
Keywords: import, from, as
- import: Kisi module ko import karne ke liye.
- from ... import: Specific function ko import karne ke liye.
- as: Module ka short name assign karne ke liye.
8. Logical Operators
Keywords: and, or, not, is, in
- and: Jab dono conditions true honi chahiye.
- or: Jab koi ek condition true ho.
- not: Condition ko ulta (reverse) kar deta hai.
- is: Object identity check karta hai.
- in: Check karta hai ki ek value kisi sequence me hai ya nahi.
9. Object-Oriented Programming (OOP)
Keywords: class, self, super
- class: Blueprint hota hai object banane ke liye.
- self: Current object ka reference hota hai.
- super: Parent class ke methods ko access karne ke liye use hota hai.
Summary
Important Keywords:
- Conditional Statements: if, elif, else
- Loops: for, while, break, continue, pass
- Functions: def, return, lambda
- Lists & Arrays: append, insert, remove, sort, pop, extend
- Exception Handling: try, except, finally, raise
- File Handling: open, read, write, with
- Modules Import: import, from, as
- Logical Operators: and, or, not, is, in
- OOP Concepts: class, self, super