In Python, variables are used to store data values. A variable is created the moment you assign a value to it, and you don’t need to declare its type explicitly. Python supports several data types:
- Numeric Types:
int
(integer),float
(floating-point number),complex
(complex numbers). - Sequence Types:
list
,tuple
,range
. - Text Type:
str
(string). - Mapping Type:
dict
(dictionary). - Set Types:
set
,frozenset
. - Boolean Type:
bool
(True or False). - Binary Types:
bytes
,bytearray
,memoryview
.
Example:
# Variable assignment
x = 10 # int
y = 3.14 # float
name = "Alice" # str
is_active = True # bool
# Printing variable types
print(type(x)) # Output: <class 'int'>
print(type(y)) # Output: <class 'float'>
print(type(name)) # Output: <class 'str'>
print(type(is_active)) # Output: <class 'bool'>