Data Types
In Python, data types are crucial for defining the nature of values, allowing logical operations with compatible values. This README provides an overview of the most common data types in Python along with code snippets and examples.
Numeric Types
Integer
An integer represents any whole number, positive or negative.
my_integer = 10
Float
A float represents any decimal number.
my_float = 5.5
Imaginary
Imaginary numbers are represented with j
in Python.
my_imaginary = 2j
Boolean Types
Boolean types represent two states: True or False.
is_connected = True
has_money = False
String Types
Strings represent textual data and can be written in single or double quotes.
my_string = "Hello, Bob"
Sequence Types
List
A list is a mutable sequence type.
numbers = [1, 2, 3, 4]
Tuple
A tuple is an immutable sequence type.
coordinates = (2.5, 1.0)
Mapping Types
Dictionary
A dictionary is a mapping type that uses key-value pairs.
users = {"Mario": 1, "Luigi": 2}
Set Types
Set
A set is an unordered collection without duplicate elements.
my_set = {10, 25, 50}
Frozen Set
A frozen set is an immutable version of a set.
frozen_set = frozenset([1, 2, 3])