Variables and Data Types
Variables are containers for storing data values. Python has no command for declaring a variable; it is created the moment you first assign a value to it.
x = 5
y = "John"
print(x)
print(y)
Built-in Data Types
In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default:
- Text Type:
str - Numeric Types:
int,float,complex - Sequence Types:
list,tuple,range - Mapping Type:
dict - Set Types:
set,frozenset - Boolean Type:
bool
Examples of Data Types
# String
greeting = "Hello World"
# Integer
age = 20
# Float
price = 19.99
# List (ordered and changeable)
fruits = ["apple", "banana", "cherry"]
# Tuple (ordered and unchangeable)
coordinates = (10, 20)
# Dictionary (key-value pairs)
person = {"name": "John", "age": 36}
# Boolean
is_active = True