Variables and Data Types in Python
1. Variables
- Variables are used to store and manage data in a program.
- They are like containers that hold values or references to values.
- In Python, you don't need to declare the data type explicitly; it is dynamically inferred.
Example:
# Variable assignment
age = 25
name = "John"
height = 5.9
# Multiple assignment
x, y, z = 10, 20, 30
2. Data Types
Python has several built-in data types:
a. Numeric Types
- int: Integer type (e.g., 5, -10)
- float: Floating-point type (e.g., 3.14, -0.5)
b. Text Type
- str: String type (e.g., "Hello, World!")
c. Boolean Type
- bool: Boolean type (True or False)
d. Sequence Types
- list: Ordered, mutable collection (e.g., [1, 2, 3])
- tuple: Ordered, immutable collection (e.g., (1, 2, 3))
e. Set Types