100 Days of Python โ Day 3. Basic types, edge cases around integers and floats, and the four container types, tested interactively in a Jupyter Notebook.
This session covers the fundamental data types in Python, tested interactively in a Jupyter Notebook. Python organizes its data types into three broad categories, and this note walks through each of the Basic Types with hands-on examples of behavior/edge cases (especially around integers and floats), followed by Container Types.
Python supports 3 categories of data types:
| Category | Types Included |
|---|---|
| Basic Types | integer, float, complex, boolean, string |
| Container Types | list, tuple, set, dictionary |
| User-defined Types | class |
int)Python integers have no fixed size limit โ they support arbitrary precision, unlike languages like C/Java where int overflows at a fixed bit-width.
# integer
print(4)
print(50000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
Output:
4
50000000000000000000000000000000000000000000000000000000000000000000000000000000000000
๐ก Key Point: Python int can grow arbitrarily large without overflow โ it automatically handles big numbers.
Testing with scientific notation:
print(4)
print(1e308)
Output:
4
1e+307
1e+307 even though the input was 1e308; note that 1e308 in Python is actually parsed as a float (scientific notation literals are always floats, not ints), which is why the behavior differs from a plain integer.print(4)
print(1e309)
Output:
4
inf
โ ๏ธ Important:1e309exceeds the maximum value a Python float can represent, so it overflows toinf(infinity).
float)Floats have a maximum representable value (~1.7 ร 10ยณโฐโธ). Beyond that, floats overflow to inf.
# float
print(4.5)
print(1.7e308)
Output:
4.5
1.7e+308
๐ก Key Point:1.7e308is approximately the maximum value a Python float can hold. Going beyond it (e.g.,1e309) results ininf.
bool)# boolean
print(True)
print(False)
Output:
True
False
complex)# complex
print(4+5j)
Output:
(4+5j)
Complex numbers in Python are written with a j suffix representing the imaginary part.
str)Strings can be declared using single quotes, double quotes, or triple quotes โ all produce the same result.
# string
print('Kolkata')
print("Kolkata")
print("""Kolkata""")
Output:
Kolkata
Kolkata
Kolkata
๐ก Key Point: Triple quotes ("""...""") are typically used for multi-line strings or docstrings, but work the same as single/double quotes for simple one-line strings.
list)Ordered, mutable collection โ defined with square brackets [].
# list
print([1,2,3,4,5])
Output:
[1, 2, 3, 4, 5]
tuple)Ordered, immutable collection โ defined with parentheses ().
# tuple
print((1,2,3,4,5))
Output:
(1, 2, 3, 4, 5)
set)Unordered collection of unique elements โ defined with curly braces {}.
# sets
print({1,2,3,4,5})
Output:
{1, 2, 3, 4, 5}
dict)Key-value pair collection โ defined with curly braces {} using key: value syntax.
# dict
print({"Name":"Nitish","Age":30,"gender":"Male"})
Output:
{'Name': 'Nitish', 'Age': 30, 'gender': 'Male'}
# Basic Types
print(4) # int
print(4.5) # float
print(True) # bool
print(4+5j) # complex
print('Kolkata') # str
# Container Types
print([1,2,3,4,5]) # list -> mutable, ordered
print((1,2,3,4,5)) # tuple -> immutable, ordered
print({1,2,3,4,5}) # set -> unordered, unique values
print({"Name":"Nitish"}) # dict -> key-value pairs
1.7e308); anything beyond that becomes inf.1e308) are treated as floats, not ints.'...', double "...", or triple """...""" quotes interchangeably for simple strings.[ ]( ){ }{key: value}int โ no size limit.float โ max ~1.7e308, overflow โ inf.bool โ True / False.complex โ written as a+bj.str โ 3 ways to declare (single/double/triple quotes).list [ ], tuple ( ), set { } (unique), dict {key: value}.Python has 3 categories of data types: Basic (int, float, bool, complex, str), Container (list, tuple, set, dict), and User-defined (class).
int โ no upper limit, grows arbitrarily large.float โ capped near 1.7e308; beyond that becomes inf.bool โ True/False.complex โ a+bj format.str โ single, double, or triple quotes โ same result.list [ ] mutable & ordered | tuple ( ) immutable & ordered | set { } unordered & unique | dict {k:v} key-value pairs.