Friday, October 17, 2025

Python's built-in immutable and mutable types for variables.

 Python Built-in Variable Types (Data Types)

Python variables can hold values of various built-in data types. These are categorized broadly as follows:Numeric Types
  • int: Integers (e.g., 42, -10).
  • float: Floating-point numbers (e.g., 3.14, -2.5).
  • complex: Complex numbers (e.g., 3 + 4j).
Sequence Types
  • str: Strings (e.g., "hello", 'world').
  • list: Mutable lists (e.g., [1, 2, 3]).
  • tuple: Immutable tuples (e.g., (1, 2, 3)).
Mapping Type
  • dict: Dictionaries (key-value pairs, e.g., {"key": "value"}).
Set Types
  • set: Mutable unordered sets (e.g., {1, 2, 3}).
  • frozenset: Immutable unordered sets (e.g., frozenset([1, 2, 3])).
Other Types
  • bool: Boolean values (True or False).
  • NoneType: The None object (represents no value).
These types are determined dynamically (Python is dynamically typed), and you can check a variable's type using the type() function, e.g., type(42) returns <class 'int'>. For more advanced or user-defined types, Python supports classes and objects via OOP.

Lecture Notes: Optimising Numerical Code

Lecture Notes: Optimising Numerical Code Prerequisites: Basic Python programming Understanding of NumPy arrays and vector ...