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.

⏱ 20 min• BeginnerPrerequisite: Variables

WHAT: four daily-use types

int

Whole number: items = 8. Count, rank aur quantity ke liye.

float

Decimal number: rating = 4.7. Price, percentage aur measurements ke liye.

str

Text: city = "Lucknow". Quotes ke andar ki value.

bool

True ya False: is_paid = False. Yes/no state aur decisions ke liye.

WHY: operation value se nahi, type se decide hota hai

python▶ Run
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.1

type() is aapka inspection tool: doubt ho to Python se directly poochho ki value kis type ki hai.

Try it: type detectiveValues change karke observe karo
Run Python dabayein

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.

python▶ Run
marks_from_form = "88"
marks = int(marks_from_form)

print(marks + 12) # 100
print("Score: " + str(marks))
!
Conversion validate bhi karni hoti hai. 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.

🎓
Guido-style insight: Python dynamically typed hai kyunki Guido chahte the: pehle socho kya karna hai, type ka jhanjhat baad me. type() se kabhi bhi pooch sakte ho — type chhupta nahi.
python▶ Run
# Unpythonic: type ka darr
# if type(x) == int: ...

# Pythonic: kaam bolo, type Python sambhalega
x = 10
print(type(x))  # 
x = "ab text"
print(type(x))  #  (badal gaya!)

MNC tip: type() == ki jagah isinstance(x, int) likho — inheritance me kaam aata hai.

Common mistakes

Data type intuition build ho gayi?

Ab strings ko deeply dekho — text Python mein sequence bhi hai, sirf sentence nahi.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course