Lesson 03 � Foundation
VALUE KA
NATURE SAMJHO.
Har value same tarah behave nahi karti. 25 ko add kar sakte ho; "25" text hai. Type samajhna bugs se bachne aur right operation choose karne ka shortcut hai.
WHAT: four daily-use types
Whole number: items = 8. Count, rank aur quantity ke liye.
Decimal number: rating = 4.7. Price, percentage aur measurements ke liye.
Text: city = "Lucknow". Quotes ke andar ki value.
True ya False: is_paid = False. Yes/no state aur decisions ke liye.
WHY: operation value se nahi, type se decide hota hai
print(2 + 3) # 5, number addition
print("2" + "3") # 23, text joining
price = 499
discount = 0.10
final_price = price * (1 - discount)
print(final_price) # 449.1type() is aapka inspection tool: doubt ho to Python se directly poochho ki value kis type ki hai.
Casting: consciously type convert karo
Kabhi data text form mein milta hai, lekin calculation ke liye number chahiye. int(), float() aur str() intentional conversion karte hain.
marks_from_form = "88"
marks = int(marks_from_form)
print(marks + 12) # 100
print("Score: " + str(marks))int("eighty") error dega, kyunki text valid integer format mein nahi hai. Later exceptions module mein isi ko gracefully handle karoge.Quick check
Integer 10 ko decimal/float mein convert karne ki valid expression likho.
Float banane wala built-in function yaad karo.
Common mistakes
- Text number ko actual number samajhna:
"10" + "5"15 nahi,105deta hai. - Money ke liye float ko blindly trust karna; production apps mein decimal handling better hoti hai.
- Boolean ko string
"False"se confuse karna. Quotes ke saath woh text hai, boolean nahi.
Ab strings ko deeply dekho�text Python mein sequence bhi hai, sirf sentence nahi.