# Variables, values & types

Code With Purpose · Hinglish · Free starter lesson

## Concept

Variable ko ek naam ki tarah samjho jo kisi object se juda hai. score = 10 mein score naam integer 10 ko refer karta hai. Python mein type pehle declare nahi karna padta. type(score) se current object ka type check kar sakte ho. Dobara assignment karne par naam naye object ko refer karega.

Whole numbers ke liye int, decimal approximations ke liye float, text ke liye str aur True/False ke liye bool use hota hai. "10" text hai; 10 number hai. input() hamesha text deta hai. Calculation karni ho toh zarurat ke hisaab se int() ya float() se convert karo.

lessons_completed jaise clear names rakho. = value assign karta hai, == comparison karta hai. int("hello") se ValueError aayega, kyunki har text valid number nahi hota. User input ko validate karo.

## Example

```python
name = "Ashu"
lessons_completed = 3
total_lessons = 12
progress = lessons_completed / total_lessons * 100
print(type(lessons_completed).__name__)
print(f"{name}: {progress:.0f}% complete")
```

## Expected output

```text
int
Ashu: 25% complete
```

## Exercise

price = 49.0 aur quantity = 3 banao. Total calculate karke print karo. Agar price "49.0" text ho toh kya change karna padega?

## Suggested solution

```
price = 49.0
quantity = 3
print(price * quantity)  # 147.0
text_price = "49.0"
print(float(text_price) * quantity)  # 147.0
```

## Takeaway

Naam objects ko refer karte hain; calculation se pehle type samjho.

Reference: https://docs.python.org/3/tutorial/introduction.html

https://codewithpurposeai.in/lesson-python-variables.html?lang=hinglish
