<class 'int'>
๐น 11. Type Conversion (Casting)
Sometimes you need to convert one data type into another.
String โ Integer
age = "25"
print(int(age))
Integer โ Float
marks = 95
print(float(marks))
Float โ Integer
price = 199.99
print(int(price)) # Output: 199
Integer โ String
number = 100
print(str(number))
๐น 12. Multiple Variable Assignment
Assign multiple variables in one line.
x, y, z = 10, 20, 30
Assign the same value to multiple variables.
a = b = c = 100
๐น 13. Dynamic Typing
Python is dynamically typed.
This means a variable can store different data types at different times.
x = 10
x = "Data Science"
print(x)
# Output: Data Science
๐น 14. Best Practices
โ Use meaningful variable names.
student_name = "Rahul"
monthly_salary = 50000
Instead of:
a = "Rahul"
b = 50000
Follow the snake_case naming convention.
Examples: customer_name, total_sales, average_salary
๐น 15. Real-World Example
name = "Rohit"
age = 25
salary = 65000.50
is_employee = True
print(name)
print(age)
print(salary)
print(is_employee)
Output:
Rohit
25
65000.5
True
๐ฏ Key Takeaways
โ Variables are used to store data.
โ Python automatically detects data types.
โ The most common data types are: int, float, str, bool, complex
โ Use type() to check a variable's data type.
โ Use meaningful variable names and follow the snake_case naming convention.
Mastering variables and data types is the first step toward becoming a successful Data Scientist. Every machine learning model, data analysis project, and AI application starts with understanding how data is stored and managed in Python.
Double Tap โค๏ธ For More