Python Introduction & Setup
Python is a high-level, interpreted, general-purpose, dynamically typed, multi-paradigm programming language. It was conceived in December 1989 by Dutch computer scientist Guido van Rossum at the Centrum Wiskunde & Informatica (CWI) in Amsterdam, Netherlands. Guido designed Python as a successor to the ABC programming language, specifically aiming to create a syntax that prioritized human developer readability and productivity over machine micro-optimization.
The name "Python" was not inspired by the reptile, but by Guido's admiration for the BBC comedy television series Monty Pythonβs Flying Circus. Guido wanted programming in Python to feel expressive, fun, and accessible to engineers and researchers worldwide.
Key Characteristics of Python:
- Interpreted & Bytecode Compiled: Python source files are compiled to intermediate bytecode (.pyc) and executed on a virtual machine (PVM).
- Dynamically Typed: Variables are bound to heap objects at runtime without requiring static type annotations.
- Multi-Paradigm: Supports Object-Oriented Programming (OOP), Procedural Programming, and Functional Programming paradigms seamlessly.
- Batteries Included: Ships with an extensive Standard Library providing built-in modules for file I/O, mathematical computing, regular expressions, JSON serialization, HTTP networking, and concurrency.
Python's guiding architectural principles are immortalized in PEP 20 β The Zen of Python by software engineer Tim Peters. You can print these 19 guiding aphorisms directly from within any Python interpreter using the easter-egg this module:
# Import Python's built-in design philosophy (PEP 20)
import this
import this: Loads the built-in CPython easter egg module which decodes and displays the 19 core Zen aphorisms (such as "Beautiful is better than ugly", "Explicit is better than implicit", "Simple is better than complex", and "Readability counts").
Unlike traditional languages like C, C++, or Java that require boilerplate classes, static methods, and import headers just to print text, Python has zero ceremony. You write executable statements directly at top-level scope.
The built-in print() function evaluates one or more expressions passed to it, converts them to UTF-8 strings, and writes the resulting character stream to the standard output buffer (sys.stdout):
# Print a friendly welcome message to the terminal screen
print("Hello, World! π Welcome to Python 3.")
# Print a friendly...: This is a comment. Python's tokenizer completely strips out any line beginning with#.print(...): A built-in Python function that outputs data to the console terminal."Hello, World! π...": A string literal enclosed in double quotes. Single quotes'...'work identically.
Hello, World! π Welcome to Python 3.A variable in Python is a named reference pointing to an object stored in heap memory. In Python, you never declare explicit data types (like int x = 10;). Instead, Python infers the type dynamically upon assignment using the = assignment operator.
When you pass multiple arguments separated by commas into print(), Python automatically joins each argument with a default space character:
# Step 1: Create variables to store student details
student_name = "Balaji" # String (Text data)
course_name = "Python Masterclass" # String
batch_year = 2026 # Integer (Whole number)
# Step 2: Print variables together on the screen
print("Student Name:", student_name)
print("Enrolled in:", course_name, "| Batch Year:", batch_year)
student_name = "Balaji": Creates a string object"Balaji"in memory and points the namestudent_nameto it.batch_year = 2026: Stores integer2026in variablebatch_year.print("Student Name:", student_name): Python prints"Student Name:"followed by a space, then the value"Balaji".
By default, the print() function behavior is governed by two built-in keyword parameters:
sep=" ": The separator placed between multiple comma-separated arguments (default is a single space).end="\n": The string appended after the last argument (default is a newline, which causes subsequent prints to start on a fresh line).flush=False: Controls whether the standard output buffer is flushed immediately to the terminal.
# 1. Custom separator using sep parameter
print("Apple", "Banana", "Orange", "Mango", sep=" - ")
# 2. Custom end parameter keeping next print on the SAME line
print("Downloading files", end="... ")
print("Done! 100% Complete β
")
- Line 2 prints:
Apple - Banana - Orange - Mango(joined by-instead of space). - Line 5 prints
Downloading files...without a newline, allowing Line 6'sDone! 100% Complete βto appear right beside it on the same line!
Python functions as an interactive scientific calculator. Expressions containing arithmetic operators (+, -, *, /, **) are evaluated according to standard operator precedence and can be printed directly:
# Define pricing parameters
item_price = 150
quantity = 3
discount = 50
# Calculate total bill
total_bill = (item_price * quantity) - discount
# Display results
print("Item Price: Rs.", item_price)
print("Quantity Ordered:", quantity)
print("Final Total Bill (after Rs. 50 discount): Rs.", total_bill)
Multiplication 150 * 3 = 450 occurs first inside parentheses, then subtraction 450 - 50 = 400, storing integer 400 in total_bill.
A common misconception is that Python interprets raw text line-by-line. In standard CPython (the official C-based reference implementation), execution proceeds in two distinct phases:
Step 1: Bytecode Compilation: Source code is tokenized, parsed into an Abstract Syntax Tree (AST), and compiled into intermediate bytecode instructions (.pyc cached files in __pycache__/).
Step 2: Python Virtual Machine (PVM): A giant evaluation loop written in C reads opcodes sequentially and dispatches corresponding C functions to execute on your machine's CPU.
In legacy Python 2, print was a statement (e.g. print "Hello"). In modern Python 3, print() is a function and parentheses are strictly mandatory. Writing print "Hello" will result in a SyntaxError: Missing parentheses in call to 'print'.
Declare variables for student name and human age. Calculate age in dog years (human_age * 7) and print formatted results.
student_name = "Alex"
human_age = 20
dog_years = human_age * 7
print("Student Name:", student_name)
print("Human Age:", human_age)
print("Dog Years Age:", dog_years)
Q Is Python interpreted or compiled?
Python is both: source code is first compiled to intermediate bytecode (.pyc), which is then interpreted and executed by the Python Virtual Machine (PVM).
Q Why did Python 3 break backward compatibility with Python 2?
Python 2 suffered from broken Unicode handling (ASCII vs Unicode confusion), integer division truncating by default (5/2 = 2), and inconsistent APIs. Python 3 standardized clean UTF-8 Unicode by default, modern iterator pipelines, and uniform syntax.
Q Can Python be compiled to native machine code like C/C++?
Standard CPython uses a VM. However, tools like Cython, Numba (JIT compilation for numerical code), and PyPy (JIT-compiled Python implementation) can compile Python or Python-like code directly to high-speed native CPU machine instructions.