Day 02 - Class Work

Understanding Variables and Data Types in Python

Apple Brochure

Apple

Apple Brochure Data

Attribute Value
fruit_name apple
fruit_color red
quantity_kg 6
price_rupees 120.5
healthy True

Apple Brochure in Python

In Python, we can store this data using variables as shown below:

fruit_name = "apple"
fruit_color = 'red'
quantity_kg = 6
price_rupees = 120.5
healthy = True

Data Types

Example values Data type
"apple", "red", "my name is ramesh" str
12, 18000, -250 int
120.5, 3.14, -0.5 float
True, False bool

Checking Data Types

We can check the data type of a variable using the type() function:

print(type(fruit_name))
print(type(fruit_color))
print(type(quantity_kg))
print(type(price_rupees))
print(type(healthy))

Printing Values

To display the values stored in the variables:

print(f"Fruit name is {fruit_name}")
print(f"Fruit color is {fruit_color}")
print(f"Quantity in kg is {quantity_kg}")
print(f"Price in rupees is {price_rupees}")
print(f"Is it healthy? {healthy}")