Introduction
Agar aap Python programming start kar rahe ho, toh sabse important foundation hai:
Variables
Data Types
Typecasting
User Input
Comments & Print
Operators
Ye sab concepts milke aapko strong base dete hain, jisse aap real-world applications bana sakte ho.
Variables & Data Types in Python
📌 Variable kya hota hai?
Variable ek container hai jo data store karta hai.
👉 Real life example:
Kitchen me dabba (container)
Usme sugar, rice, coffee store hota hai
Same way:
Variable me data store hota hai
age = 34
name = "Harry"
gpa = 8.2
Data Types in Python
Python automatically data type detect karta hai (Dynamic Typing)
Common Data Types:
Type | Example | Meaning |
|---|---|---|
int | 10 | Integer |
float | 8.5 | Decimal number |
str | "Hello" | Text |
bool | True/False | Logical |
print(type(age)) # int
print(type(name)) # str
📏 Variable Naming Rules
✔ Valid:
age = 20
_name = "test"
abc_123 = 10
❌ Invalid:
34age = 10 # number se start nahi
age$ = 10 # special char allowed nahi
Rules:
Letter ya underscore se start hona chahiye
Numbers allowed hain (start me nahi)
Case sensitive hai (
age≠Age)
💡 Pro Tip (Developer Insight)
Meaningful names use karo:
user_age = 25 # better than a = 25
Avoid Python keywords:
# avoid this
if = 10
Typecasting (Data Type Conversion)
Typecasting kya hota hai?
Ek data type ko dusre data type me convert karna.
👉 Example:
b = "34" # string
c = int(b) # integer
Common Typecasting Functions
Function | Use |
|---|---|
int() | convert to integer |
float() | convert to decimal |
str() | convert to string |
bool() | convert to boolean |
📌 Example
d = 223
e = str(d)
print(type(e)) # str
⚠️ Common Mistake
a = "10"
print(a + 5) # ❌ error
✔ Fix:
a = int(a)
print(a + 5)
💡 Real World Use
Form inputs (always string aata hai)
API responses
Database data processing
⌨️ User Input in Python
📌 Input Function kya hai?
User se data lene ke liye use hota hai.
a = input("Enter number: ")
👉 Input always string return karta hai
⚠️ Important Concept
a = input("Enter number: ")
print(a + 3) # ❌ error
✔ Correct:
a = int(input("Enter number: "))
print(a + 3)
📌 Multiple Inputs Example
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(a + b)
💡 Best Practice
Always prompt use karo:
input("Enter your name: ")
💬 Comments, Print & Escape Sequences
📝 Comments kya hote hain?
Code me notes likhne ya kisi line ko ignore karne ke liye.
# This is a comment
Multi-line:
'''
This is multi-line comment
'''
🖨️ Print Function Advanced Use
print("Hello", "World")
Default:
space add hota hai
Customize:
print("Hello", "World", sep="-")
Output:
Hello-World
🔚 end Parameter
print("Hello", end=" ")
print("World")
Output:
Hello World
🔤 Escape Sequence Characters
Code | Meaning |
|---|---|
\n | new line |
\t | tab |
\ | backslash |
print("Hello\nWorld")
➕ Operators in Python
🔢 Arithmetic Operators
a = 34
b = 2
print(a + b) # 36
print(a - b) # 32
print(a * b) # 68
print(a / b) # 17.0
print(a % b) # remainder
print(a // b) # floor division
print(a ** b) # power
⚖️ Comparison Operators
print(a > b) # True
print(a == b) # False
print(a != b) # True
👉 Always returns Boolean (True/False)
🔗 Logical Operators
print(True and False) # False
print(True or False) # True
print(not True) # False
🧮 Assignment Operators
a = 10
a += 5 # 15
a -= 3 # 12
a *= 2 # 24
💡 Developer Tips
==vs=confusion avoid karoFloor division (
//) interviews me pucha jata haiBoolean logic backend filtering me useful hota hai
🧑💻 Practical Tips (Real World)
✔ Common Mistakes
Input ko integer convert na karna
Variable naming confusing rakhna
=aur==mix kar dena
✔ Best Practices
Clean code likho
Comments use karo
Small programs likh ke practice karo
✔ Interview Questions
Python dynamic typing kya hai?
Difference between
=and==?//vs/difference?Input always string kyun hota hai?
📌 Summary
Aaj humne Python ke core basics cover kiye:
Variables = data containers
Data Types = int, float, string, bool
Typecasting = data conversion
Input = user se data lena
Comments = code readability
Operators = calculations & logic
👉 Ye sab concepts milke Python ka strong foundation banate hain.
🏁 Final Advice
Programming ratne ka game nahi hai — samajhne ka game hai.
👉 Roz thoda code likho, tabhi mastery aayegi.