Home > Python > Introduction to Python

Ch. 1.1 Print Function

Chapters Index
Program 1

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function

Python 3.11 Ready

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

Print Function: Standard Console Output & Scientific Data Formatting

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

1. Core Principles & Theoretical Framework

Standard Output Interface: In computational science, print() routes numerical metrics, simulation variables, and physical states to standard output (stdout).
Formatting Precision: F-strings (f"{val:.4e}") enable exact scientific exponential notation, while f"{val:.3f}" specifies decimal width matching significant figures.
Tabular Alignment: Multi-column scientific data streams can be cleanly aligned using format widths (f"{t:>8.2f} {x:>12.4e}").

2. Mathematical Formulation & Algorithmic Pipeline

Scientific output demands strict adherence to experimental uncertainties and significant figures:

$$ x = (x_0 \pm \delta x) \times 10^n \quad \implies \quad \text{Formatted as: } \texttt{f"\{x_0:.2f\}e\{n\}"} $$
1. Raw Float → 2. Precision Specifier (:.e or :.f) → 3. Aligned Terminal Column

3. Numerical Mechanics & Implementation Logic

  • Standard Stream: Use print(*objects, sep=' ', end='\n') to emit computed states.
  • Significant Figures: Match format specifier to measurement accuracy (avoid displaying spurious 16-digit machine decimals).
  • Multi-variable Output: Combine multiple physical variables into a single formatted output line inside time loops.

4. Relevant Computational Practice Exercises

Exercise 1
Write a script to print physical constants ($c, \hbar, G, k_B$) neatly formatted in scientific notation with four significant figures.
Exercise 2
Construct a formatted ASCII table displaying angles from $0^\circ$ to $90^\circ$ in $15^\circ$ increments alongside their sine and cosine values.
Exercise 3
Format an experimental measurement report displaying value, absolute uncertainty, and percentage relative uncertainty.
Standard Literature & References:
  • Hans Petter Langtangen, "A Primer on Scientific Programming with Python", Springer (2016).
  • Mark Newman, "Computational Physics", University of Michigan (2013).