Variables Data Types
In Python, variables are used to store data, and data types define what kind of data is stored. This is the first and most essential building block of your data science journey.
1️⃣ What is a Variable?
A variable is like a label for data stored in memory. You can assign any value to a variable and reuse it throughout your code.
Syntax:
x = 10
name = "Riya"
is_active = True
2️⃣ Common Data Types in Python
• int – Integers (whole numbers)
age = 25
• float – Decimal numbers
height = 5.8
• str – Text/String
city = "Mumbai"
• bool – Boolean (True or False)
is_student = False
• list – A collection of items
fruits = ["apple", "banana", "mango"]
• tuple – Ordered, immutable collection
coordinates = (10.5, 20.3)
• dict – Key-value pairs
student = {"name": "Riya", "score": 90}3️⃣ Type Checking
You can check the type of any variable using
type() print(type(age)) # <class 'int'>
print(type(city)) # <class 'str'>
4️⃣ Type Conversion
Change data from one type to another:
num = "100"
converted = int(num)
print(type(converted)) # <class 'int'>
5️⃣ Why This Matters in Data Science
Data comes in various types. Understanding and managing types is critical for:
• Cleaning data
• Performing calculations
• Avoiding errors in analysis
✅ Practice Task for You:
• Create 5 variables with different data types
• Use
type() to print each one • Convert a string to an integer and do basic math
💬 Tap ❤️ for more!