Python Data Types#
Python has various data types, each with its own unique characteristics and purposes.
I will explain the main data types.
1. Numeric Types#
- Integer (
int): An integer data type. It includes both positive and negative numbers and has no size limit.
a = 10
b = -5- Floating Point (
float): A floating-point data type that includes decimal points.
c = 3.14
d = -0.5- Complex Numbers (
complex): A complex number data type with a real part and an imaginary part.
The imaginary part is represented using j.
e = 1 + 2j2. Sequence Types#
- String (
str): A collection of characters enclosed in single quotes (’) or double quotes (").
f = "Hello, World!"- List (
list): A mutable sequence type that stores multiple values in order.
It is defined using square brackets ([ ]) and can include different data types.
g = [1, 2, 3, 'a', 'b', 'c']- Tuple (
tuple): Similar to a list but immutable.
It is defined using parentheses (( )).
h = (1, 2, 3, 'a', 'b', 'c')3. Set Types#
- Set (
set): A collection of unique elements.
It is unordered and defined using curly braces ({ }).
i = {1, 2, 3, 4, 5}- frozenset: An immutable set.
It is created using the frozenset() function.
j = frozenset([1, 2, 3, 4, 5])4. Mapping Types#
- Dictionary (
dict): A collection of key-value pairs.
It is defined using curly braces ({ }) and the keys must be unique.
k = {'name': 'Alice', 'age': 25}5. Other Types#
- Boolean (
bool): A type that represents True and False.
l = True
m = FalseNone: A type that represents the absence of a value.
n = None