A variable in Python is a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name.
x = 10 y = "Hello, World!"
In the example above, x is a variable that holds an integer value 10, and y is a variable that holds a string value "Hello, World!".
Python Data Types
Python supports various data types. Some of the most commonly used data types include:
- Integers (
int): Whole numbers without a fractional part. - Floating-point numbers (
float): Numbers with a fractional part. - Strings (
str): A sequence of characters. - Booleans (
bool): RepresentsTrueorFalse. - Lists (
list): An ordered collection of values. - Tuples (
tuple): An ordered, immutable collection of values. - Dictionaries (
dict): A collection of key-value pairs.
#integers (int)
age = 25
#floating point (float)
temperature = 98.6
#String (str)
name = "Alice"
#booleans (bool)
is_active = True
#Lists (list)
fruits = ["apple", "banana", "cherry"]
#Tuples (tuple)
coordinates = (10.0, 20.0)
#Dictionaries (dict)
person = {"name": "John", "age": 30}
