BASIC PYTHON
🐍 Python – Complete Basic Notes
Syntax, Variables, Data Types, Operators, Conditionals, Loops, Functions aur Collections ka complete quick guide.
1️⃣ Python Kya Hai?
Definition: Python ek high-level, general-purpose aur beginner-friendly programming language hai jise padhna aur likhna English jaisa aasan hota hai.
- Readable Syntax: Complex symbols (jaise
{}ya;) ki jagah clean indentation (spaces) use karta hai. - Interpreted: Code line-by-line execute hota hai, isliye errors jaldi pakad me aate hain.
- Industry Use: Backend Web Development, Artificial Intelligence (AI), Machine Learning (ML), Data Analysis aur Automation me sabse zyada popular.
2️⃣ Python Ke Core Features
- Simple & Easy: Beginners ke coding shuru karne ke liye best language.
- Dynamically Typed: Variables ka data type manually declare nahi karna padta, Python value dekh kar khud decide kar leta hai.
- Rich Standard Library: Har task ke liye hazaron ready-made packages aur built-in modules available hain.
- Cross-Platform: Windows, macOS aur Linux par bina change kiye same run hota hai.
3️⃣ First Python Program
Ek file banayein app.py aur usme yeh line likhein:
print("Hello Python World!")
Terminal me run karne ke liye likhein:
python app.py
4️⃣ Variables & Data Types
Python me variable declare karne ke liye koi keyword (jaise var ya int) nahi lagta:
name = "Rahul" # str (Text)
age = 20 # int (Whole Number)
height = 5.7 # float (Decimal Number)
is_student = True # bool (True ya False)
| Data Type | Example | Description |
|---|---|---|
str |
"Python", 'Code' |
Text characters enclosed in quotes |
int |
10, -45, 1000 |
Bina decimal wale positive ya negative numbers |
float |
3.14, -0.5 |
Decimal fraction wale numbers |
bool |
True, False |
Logical state (Pehla letter Capital hota hai) |
5️⃣ Operators
Values aur variables par calculation ya logic execute karne ke symbols:
| Type | Symbols | Example | Meaning |
|---|---|---|---|
| Arithmetic | +, -, *, /, % |
10 % 3 |
Modulus (Remainder = 1) |
| Assignment | =, +=, -=, *= |
x += 5 |
Same as x = x + 5 |
| Comparison | ==, !=, >, <, >= |
age >= 18 |
Result True ya False deta hai |
| Logical | and, or, not |
x > 5 and y < 10 |
English words use karta hai (No && or ||) |
6️⃣ Conditionals (if, elif, else)
Decisions lene ke liye Python Indentation (4 spaces) use karta hai curly brackets {} ki jagah:
age = 20
if age >= 18:
print("Eligible to Vote (Adult)")
elif age >= 13:
print("Teenager")
else:
print("Minor")
if ya colon : ke baad aane wali lines ko thoda aage (space dekar) likhna mandatory hai. Agar indentation galat hua toh Python IndentationError dega.
7️⃣ Loops (Code Repetition)
1. For Loop (range function ke sath)
# 1 se lekar 5 tak print karega (6 exclude rehta hai)
for i in range(1, 6):
print("Count:", i)
2. While Loop (Condition check ke sath)
i = 1
while i <= 5:
print("Iteration:", i)
i += 1 # Increment lazmi hai infinite loop se bachne ke liye
8️⃣ Functions
Definition: Reusable code block jise def keyword se define kiya jata hai.
# Function Definition
def greet(name):
return "Hello, " + name + "!"
# Function Call
msg = greet("Rahul")
print(msg) # "Hello, Rahul!"
9️⃣ Lists & Dictionaries (Core Collections)
1. List (Ordered, Changeable Collection)
fruits = ["Apple", "Banana", "Mango"]
print(fruits[0]) # "Apple" (First item)
fruits.append("Orange") # Element add karta hai
print(len(fruits)) # Total length
2. Dictionary (Key-Value Pairs)
person = {
"name": "Rahul",
"age": 20,
"city": "Indore"
}
print(person["name"]) # "Rahul"
person["age"] = 21 # Value update karna
| Collection | Syntax | Access Pattern |
|---|---|---|
| List | Square Brackets [] |
Index number se: list[0] |
| Dictionary | Curly Brackets {} |
Key ke naam se: dict["key"] |