Python19th June2024 07.drawio

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Fundamental Data Types vs Immutability

Fundamental Data Types in Python

Fundamental data types (also known as built-in types or primitive types) in Python are the basic building
blocks provided by the language. These types are directly supported by Python and include:

1. Integers (int): Whole numbers, e.g., 10, -5.


2. Floating-point numbers (float): Numbers with a decimal point, e.g., 3.14, -0.001.
3. Booleans (bool): Logical values, True and False.
4. Strings (str): Text, e.g., "hello", "Python".
5. Complex numbers (complex): Numbers with a real and imaginary part, e.g., 1+2j.

Immutability in Python

Immutability refers to objects whose state cannot be changed after they are created.
Immutable objects include:

1. Integers (int)
2. Floating-point numbers (float)
3. Booleans (bool)
4. Strings (str)
5. Tuples (tuple)
6. Frozensets (frozenset)
7. Complex numbers (complex)
Fundamental Data Types vs Immutability

Key Differences
1. Nature:

Fundamental Data Type: Refers to the basic data types built into the Python language.
Immutability: Refers to the characteristic of an object that prevents modification after it is created.

2. Scope:

Fundamental Data Type: Encompasses the simplest data types provided by Python.
Immutability: Can apply to both fundamental and non-fundamental data types.

3. Mutability:

Fundamental Data Type: Some fundamental data types are mutable (like list), while others are
immutable (like int).
Immutability: Specifically concerns whether an object can be modified after creation.

4. Examples:

Fundamental Data Type: int, float, bool, str, complex.


Immutability: int, float, bool, str, tuple, frozenset, complex.

Fundamental Data Types: The basic data types built into Python (e.g., int, float, bool, str,
complex).
Immutability: A property of an object that cannot be changed after its creation. In Python, many
fundamental data types are immutable (e.g., int, float, bool, str), but this concept also applies to
more complex types like tuples and frozensets.

You might also like