Numeric Types:
Data Types: int
, float
, str
, bool
bool
class in Python handles truth values. There are only two possiblebool
values:True
andFalse
. These are written directly as literals, representing the fundamental concepts of truth and falsehood.int
class is used for whole numbers, and unlike some languages, it can handle integers of any size.float
class to represent decimal numbers. This class uses a fixed-precision mechanism, meaning there’s a limit to the precision of the numbers it can store.
Numeric Types
1# int: Represents whole numbers
2my_integer = 25
3
4# float: Represents numbers with decimal points
5my_float = 3.14
6
7# complex: Represents complex numbers with real and imaginary parts
8my_complex = 2 + 5i
Containers for Your Collections:
Sequence Types
1# str: Represents a sequence of characters (text)
2my_string = "Hello, world!"
list
: Like a grocery list, store items in order.
1# list: An ordered, mutable (changeable) collection
2my_list = [1, "apple", 3.14]
tuple
: Like a package deal, items are fixed once set.
1# tuple: An ordered, immutable (unchangeable) collection
2my_tuple = (10, 20, "hello")
dict
: Stores data with labels (keys) for easy lookup.
1# Mapping Type
2# dict: Stores data in key-value pairs
3my_dictionary = {"name": "Alice", "age": 30, "city": "New York"}
set
: Think of a bag of marbles – each one unique.
1# Set Type
2# set: An unordered collection of unique elements
3my_set = {1, 2, 3, 1, 2}
Notes:
- Built-in classes are your ready-made tools for common data types.
- Each class comes with built-in methods that make working with your data efficient and intuitive.