Home > Python > Introduction to Python

Ch. 1.2 Variable and Data Types

Chapters Index
Program 1

Variable and Data Types

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 2

Variable and Data Types

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Program 3

Variable and Data Types

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.
Theoretical Principles & Computational Physics Guide

Variables & Data Types: Dynamic Typing & Numerical Representation

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

State Representation: Variables store physical observables (mass, charge, velocity) and coordinates in computer memory.
IEEE 754 Floating-Point: Standard 64-bit double precision provides ~15-17 significant decimal digits with dynamic range $10^{-308}$ to $10^{308}$.
Complex Arithmetic: Quantum amplitudes and AC phasors are natively supported via the j suffix (e.g. 3.0 + 4.0j).

2. Mathematical Formulation & Algorithmic Pipeline

Machine precision $\epsilon_{\text{mach}}$ determines the smallest floating-point increment such that $1.0 + \epsilon \neq 1.0$:

$$ \epsilon_{\text{mach}} = 2^{-52} \approx 2.22 \times 10^{-16}, \quad z = x + iy \in \mathbb{C} \implies |z|^2 = x^2 + y^2 $$

3. Numerical Mechanics & Implementation Logic

  • Type Conversion: Apply explicit typecasting (float(), int(), complex()) to guarantee proper operator behavior.
  • Overflow & Underflow Guard: Monitor exponent scales in calculations involving extreme astronomical or quantum magnitudes.
  • Immutability & Mutation: Distinguish between immutable scalars and mutable sequence references.

4. Relevant Computational Practice Exercises

Exercise 1
Numerically determine machine epsilon $\epsilon_{\text{mach}}$ by repeatedly halving $\epsilon$ until $1.0 + \epsilon == 1.0$.
Exercise 2
Define a normalized quantum state amplitude $z = \frac{1}{\sqrt{2}} + \frac{i}{\sqrt{2}}$ and verify that $|z|^2 = 1.0$.
Exercise 3
Compare arbitrary-precision integer factorials $N!$ against standard 64-bit floating-point limits.
Standard Literature & References:
  • David Goldberg, "What Every Computer Scientist Should Know About Floating-Point Arithmetic", ACM Computing Surveys (1991).
  • Mark Newman, "Computational Physics", University of Michigan (2013).