Lecture 3 (1)
Lecture 3 (1)
Sadaf Zeeshan
Lecture 3
print("Name:", name)
print("Age:", age)
print("Height:", height, "feet")
print("Student:", is_student)
A variable is used to store data in Python. Different types of variables hold different types of
data. Below are the most common types:
1. String (str)
Example:
name = "Alice"
greeting = 'Hello, how are you?'
print(name) # Output: Alice
print(greeting) # Output: Hello, how are you?
2. Integer (int)
Example:
age = 25
temperature = -10
count = 1000
Python by Dr. Sadaf Zeeshan
x = 10
y=3
print(x + y) # Output: 13
print(x * y) # Output: 30
print(x // y) # Output: 3 (integer division)
print(x % y) # Output: 1 (remainder)
3. Float (float)
Example:
height = 5.8
price = 99.99
pi = 3.14159
print(height, price, pi) # Output: 5.8 99.99 3.14159
a = 10.5
b = 2.3
print(a + b) # Output: 12.8
print(a * b) # Output: 24.15
4. Boolean (bool)
Example:
is_raining = True
is_summer = False
print(is_raining) # Output: True
print(is_summer) # Output: False
x = 10
y = 20
print(x > y) # Output: False
print(x < y) # Output: True
print(x == y) # Output: False
5. List (list)
A list is an ordered, changeable collection of items. It can contain different data types.
Example:
List Methods
6. Tuple (tuple)
A tuple is like a list but immutable (cannot be changed after creation). Tuples are faster and
use less memory than lists.
Example:
Best Used For Collections that change frequently Fixed data sets
Real-World Example
7. Dictionary (dict)
A dictionary in Python is a data structure that stores information in key-value pairs. Unlike
lists and tuples, where data is stored in an ordered sequence, dictionaries allow quick access
to values based on unique keys.
Dictionaries are one of the most powerful and flexible data structures in Python. They allow
fast lookups, efficient storage, and easy data organization, making them essential for real-
world applications like:
Example:
Summary Table
By understanding these variables, you can store and manipulate different types of data in
Python effectively! 🚀