# Variables, values & types

Code With Purpose · English · Free starter lesson

## Concept

A variable is a name bound to an object. In score = 10, score refers to an integer object. Python does not require a type declaration; type(score) tells you the current object’s type. Reassigning score changes what the name refers to.

Use int for whole numbers, float for decimal approximations, str for text, and bool for True or False. Quotes distinguish text from a number: "10" is a string, while 10 is an integer. input() returns text, so convert deliberately with int() or float() when a calculation needs a number.

Use meaningful names such as lessons_completed. Assignment uses =; comparison uses ==. Converting invalid text, such as int("hello"), raises ValueError. Validate user input instead of assuming every entry is numeric.

## 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

Create price = 49.0 and quantity = 3. Calculate and print the total. What changes if price is "49.0" instead?

## Suggested solution

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

## Takeaway

Names refer to objects; understand the type before you calculate.

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

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