Paramclasses Academy - Blog

Tutorials Details

Variables and Data Types Tutorial for Beginners

Variables and Data Types Tutorial for Beginners

October 16, 2026

1. WHAT IS A VARIABLE?

A variable is a name used to refer to a value stored in a program.

Variables help us store and work with information such as names, ages, prices, quantities, and customer details.

Example:

name = "Rahul"
age = 25
salary = 30000

print(name)
print(age)
print(salary)

Output:

Rahul
25
30000

Explanation:

name stores the text "Rahul".
age refers to the integer 25.
salary refers to the integer 30000.

==================================================
2. WHY DO WE USE VARIABLES?
==================================================

Variables are used to:

1. Store information.
2. Reuse values in a program.
3. Perform calculations.
4. Update information when required.
5. Make programs easier to understand.
6. Manage customer, employee, product, and sales data.

REAL-TIME EXAMPLE:

A shopping application needs to store the product name, price, and quantity.

product_name = "Laptop"
price = 50000
quantity = 2

total = price * quantity

print(product_name)
print(total)

Output:

Laptop
100000

Here, variables store the product information and calculate the total price.

==================================================
3. VARIABLE NAMING RULES
==================================================

Rules for naming variables:

1. A variable name can contain letters, numbers, and underscores.
2. A variable name cannot start with a number.
3. Spaces are not allowed in variable names.
4. Variable names are case-sensitive.
5. Python keywords cannot be used as variable names.
6. Use meaningful names whenever possible.

VALID VARIABLE NAMES:

name = "Amit"
age = 25
student_name = "Ravi"
total_amount = 5000
price2 = 200

INVALID VARIABLE NAMES:

2price = 100       # Cannot start with a number
student name = "Amit"  # Spaces are not allowed
class = "Python"   # class is a Python keyword

IMPORTANT:

Python is case-sensitive.

name = "Rahul"
Name = "Amit"

print(name)
print(Name)

Output:

Rahul
Amit

==================================================
4. WHAT ARE DATA TYPES?
==================================================

A data type identifies the kind of value a variable refers to.

Python has several built-in data types.

Important beginner data types:

1. int
2. float
3. str
4. bool

Other commonly used types include:

5. list
6. tuple
7. set
8. dict
9. NoneType

==================================================
5. INTEGER (int)
==================================================

WHAT IS int?

int represents whole numbers without a decimal part.

Examples:

age = 25
quantity = 10
temperature = -5

print(age)
print(quantity)
print(temperature)

Output:

25
10
-5

REAL-TIME EXAMPLE:

Store the number of products purchased by a customer.

product_quantity = 5
print(product_quantity)

Output:

5

==================================================
6. FLOAT (float)
==================================================

WHAT IS float?

float represents numbers with a decimal part.

Examples:

price = 99.50
percentage = 85.75
temperature = 36.6

print(price)
print(percentage)
print(temperature)

Output:

99.5
85.75
36.6

REAL-TIME EXAMPLE:

Calculate the total price of a product.

price = 99.50
quantity = 3

total = price * quantity

print(total)

Output:

298.5

Note: Floating-point values can have small precision differences. For financial applications, the decimal module is often preferable.

==================================================
7. STRING (str)
==================================================

WHAT IS str?

str represents text, such as names, addresses, and messages.

Strings can be enclosed in single or double quotation marks.

Examples:

name = "Rahul"
city = 'Raipur'
message = "Welcome to Python"

print(name)
print(city)
print(message)

Output:

Rahul
Raipur
Welcome to Python

REAL-TIME EXAMPLE:

Store customer information.

customer_name = "Amit Sharma"
city = "Raipur"

print("Customer:", customer_name)
print("City:", city)

Output:

Customer: Amit Sharma
City: Raipur

==================================================
8. BOOLEAN (bool)
==================================================

WHAT IS bool?

bool represents one of two values:

True
False

Examples:

is_active = True
is_logged_in = False

print(is_active)
print(is_logged_in)

Output:

True
False

REAL-TIME EXAMPLE:

Check whether a customer account is active.

account_active = True

if account_active:
    print("Account is active")
else:
    print("Account is inactive")

Output:

Account is active

Note: True and False must begin with capital letters in Python.

==================================================
9. CHECK DATA TYPES USING type()
==================================================

WHAT IS type()?

The type() function tells us the type of a value.

SYNTAX:

type(value)

EXAMPLE:

name = "Rahul"
age = 25
price = 99.50
is_active = True

print(type(name))
print(type(age))
print(type(price))
print(type(is_active))

OUTPUT:

<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>

REAL-TIME USE:

Use type() while debugging a program to check whether a value is text, an integer, or another data type.

==================================================
10. TYPE CONVERSION
==================================================

WHAT IS TYPE CONVERSION?

Type conversion means converting a value from one data type to another when the conversion is valid.

COMMON FUNCTIONS:

int()    - Converts a suitable value to an integer.
float()  - Converts a suitable value to a float.
str()    - Converts a value to a string.
bool()   - Converts a value to a Boolean.

EXAMPLE 1: STRING TO INTEGER

age = "25"

age = int(age)

print(age)
print(type(age))

OUTPUT:

25
<class 'int'>

EXAMPLE 2: INTEGER TO FLOAT

number = 10

result = float(number)

print(result)

OUTPUT:

10.0

EXAMPLE 3: NUMBER TO STRING

price = 500

message = str(price)

print(message)
print(type(message))

OUTPUT:

500
<class 'str'>

EXAMPLE 4: STRING TO FLOAT

price = "99.50"

price = float(price)

print(price)

OUTPUT:

99.5

IMPORTANT:

Invalid conversions can cause ValueError.

Example:

age = int("hello")

This produces a ValueError because "hello" is not a valid integer representation.

==================================================
11. TAKING INPUT FROM THE USER
==================================================

WHAT IS input()?

The input() function receives information entered by a user.

IMPORTANT:

input() returns a string by default.

SYNTAX:

variable = input("Enter something: ")

EXAMPLE:

name = input("Enter your name: ")

print("Welcome", name)

SAMPLE INPUT:

Enter your name: Rahul

OUTPUT:

Welcome Rahul

REAL-TIME EXAMPLE:

Ask a customer for their name.

customer_name = input("Enter customer name: ")

print("Customer registered:", customer_name)

==================================================
12. CONVERTING USER INPUT TO NUMBERS
==================================================

Example:

age = int(input("Enter your age: "))

print("Your age is", age)

SAMPLE INPUT:

Enter your age: 25

OUTPUT:

Your age is 25

REAL-TIME EXAMPLE: BILL CALCULATION

price = float(input("Enter product price: "))
quantity = int(input("Enter quantity: "))

total = price * quantity

print("Total bill:", total)

SAMPLE INPUT:

Enter product price: 250.50
Enter quantity: 2

OUTPUT:

Total bill: 501.0

Note: Handle invalid user input in production programs using exception handling.

==================================================
13. MULTIPLE VARIABLE ASSIGNMENT
==================================================

Python allows assigning values to multiple variables in one statement.

EXAMPLE 1:

name, age, city = "Rahul", 25, "Raipur"

print(name)
print(age)
print(city)

OUTPUT:

Rahul
25
Raipur

EXAMPLE 2: SAME VALUE TO MULTIPLE VARIABLES

a = b = c = 100

print(a)
print(b)
print(c)

OUTPUT:

100
100
100

==================================================
14. UPDATING VARIABLE VALUES
==================================================

Variables can refer to new values during program execution.

EXAMPLE:

price = 100

print(price)

price = 200

print(price)

OUTPUT:

100
200

REAL-TIME EXAMPLE:

Update the price of a product.

product_price = 500

product_price = 450

print("Updated price:", product_price)

OUTPUT:

Updated price: 450

==================================================
15. CONSTANTS IN PYTHON
==================================================

WHAT IS A CONSTANT?

A constant is a value intended to remain unchanged throughout a program.

Python does not enforce ordinary variables as constants.

By convention, constant names use uppercase letters.

EXAMPLE:

TAX_RATE = 0.18
COMPANY_NAME = "My Company"

print(TAX_RATE)
print(COMPANY_NAME)

OUTPUT:

0.18
My Company

IMPORTANT:

Uppercase names communicate that a value should not be changed, but Python still allows reassignment.

==================================================
16. REAL-TIME PROJECT: EMPLOYEE DETAILS
==================================================

SCENARIO:

A company needs to store basic employee information and calculate annual salary.

PROGRAM:

employee_name = "Rahul Sharma"
employee_id = 101
monthly_salary = 30000.0
is_active = True

annual_salary = monthly_salary * 12

print("Employee Name:", employee_name)
print("Employee ID:", employee_id)
print("Monthly Salary:", monthly_salary)
print("Annual Salary:", annual_salary)
print("Active Employee:", is_active)

OUTPUT:

Employee Name: Rahul Sharma
Employee ID: 101
Monthly Salary: 30000.0
Annual Salary: 360000.0
Active Employee: True

CONCEPTS USED:

str stores employee names.
int stores the employee ID.
float stores salary values.
bool stores active status.
Variables allow values to be reused.
Arithmetic calculates annual salary.

==================================================
17. COMMON BEGINNER MISTAKES
==================================================

MISTAKE 1: USING AN UNDEFINED VARIABLE

print(username)

This causes NameError if username has not been defined.

CORRECT:

username = "Rahul"
print(username)

------------------------------------------

MISTAKE 2: ADDING A STRING AND AN INTEGER

age = "25"
print(age + 5)

This causes TypeError.

CORRECT:

age = int("25")
print(age + 5)

Output:

30

------------------------------------------

MISTAKE 3: FORGETTING THAT input() RETURNS A STRING

price = input("Enter price: ")
print(price * 2)

If the input is 10, this repeats the text and displays 1010.

CORRECT:

price = float(input("Enter price: "))
print(price * 2)

If the input is 10, the output is 20.0.

==================================================
18. PRACTICE PROGRAMS
==================================================

PROGRAM 1: PERSONAL DETAILS

Create variables for your name, age, and city.
Print all three values.

PROGRAM 2: ADD TWO NUMBERS

a = 10
b = 20

result = a + b

print(result)

Expected output:

30

PROGRAM 3: PRODUCT BILL

price = 200
quantity = 3

total = price * quantity

print("Total:", total)

Expected output:

Total: 600

PROGRAM 4: CHECK DATA TYPES

name = "Amit"
age = 22
salary = 25000.50
is_employee = True

Print the type of each variable.

PROGRAM 5: USER REGISTRATION

Ask the user for their name, age, and city.
Print the collected details.

PROGRAM 6: SALARY CALCULATOR

Ask the user for their monthly salary.
Calculate and print the annual salary.

PROGRAM 7: RECTANGLE AREA

length = 10
width = 5

Calculate:

area = length * width

Expected output:

50

PROGRAM 8: DISCOUNT CALCULATOR

original_price = 1000
discount_percent = 10

discount = original_price * discount_percent / 100
final_price = original_price - discount

print("Discount:", discount)
print("Final Price:", final_price)

Expected output:

Discount: 100.0
Final Price: 900.0

==================================================
19. MODULE 2 QUIZ
==================================================

Q1. Which data type stores whole numbers?

A. str
B. int
C. bool

Answer: B. int

Q2. Which data type stores text?

A. str
B. float
C. int

Answer: A. str

Q3. What is the result of type(10.5)?

A. int
B. str
C. float

Answer: C. float

Q4. What does input() return by default?

A. int
B. str
C. float

Answer: B. str

Q5. Which function converts a suitable string to an integer?

A. str()
B. int()
C. type()

Answer: B. int()

Q6. Which is a valid variable name?

A. 2name
B. student name
C. student_name

Answer: C. student_name

Q7. Which is a Boolean value?

A. "True"
B. True
C. 1.5

Answer: B. True

Q8. What is the output?

a = 10
b = 5
print(a + b)

Answer: 15

==================================================
20. MODULE 2 ASSIGNMENT
==================================================

Complete these tasks independently:

1. Create five variables using different data types.
2. Print each variable and its data type.
3. Take a user's name and age as input.
4. Convert numeric input into int or float.
5. Calculate a product's total price.
6. Calculate an employee's annual salary.
7. Create a discount calculator.
8. Create an employee details program.
9. Practise valid and invalid variable names.
10. Explain the difference between int, float, str, and bool.

==================================================
21. MODULE 2 SUMMARY
==================================================

In this module, you learned:

1. What variables are.
2. Why variables are used.
3. Variable naming rules.
4. Python data types.
5. int, float, str, and bool.
6. The type() function.
7. Type conversion using int(), float(), str(), and bool().
8. User input using input().
9. Multiple variable assignment.
10. Updating variables and naming constants.
11. Real-time employee and billing examples.
12. Common errors and practice programs.