Python Data Types

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.

Overview

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.

Key Concepts

Python supports 3 categories of data types:

CategoryTypes Included
Basic Typesinteger, float, complex, boolean, string
Container Typeslist, tuple, set, dictionary
User-defined Typesclass

Detailed Explanation

1. Integer (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
The output shown was 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: 1e309 exceeds the maximum value a Python float can represent, so it overflows to inf (infinity).

2. Float (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.7e308 is approximately the maximum value a Python float can hold. Going beyond it (e.g., 1e309) results in inf.

3. Boolean (bool)

# boolean
print(True)
print(False)

Output:

True
False

4. Complex (complex)

# complex
print(4+5j)

Output:

(4+5j)
Complex numbers in Python are written with a j suffix representing the imaginary part.

5. String (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.

6. List (list)

Ordered, mutable collection โ€” defined with square brackets [].

# list
print([1,2,3,4,5])

Output:

[1, 2, 3, 4, 5]

7. Tuple (tuple)

Ordered, immutable collection โ€” defined with parentheses ().

# tuple
print((1,2,3,4,5))

Output:

(1, 2, 3, 4, 5)

8. Set (set)

Unordered collection of unique elements โ€” defined with curly braces {}.

# sets
print({1,2,3,4,5})

Output:

{1, 2, 3, 4, 5}

9. Dictionary (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'}

Commands / Syntax Summary

# 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

Important Points

Things to Remember

Quick Revision

Python has 3 categories of data types: Basic (int, float, bool, complex, str), Container (list, tuple, set, dict), and User-defined (class).