Python Introduction
In this page:
What is Python?
Python is a high-level, general-purpose programming language prized for readable, near-English syntax that lets you express ideas in fewer lines than languages like C++ or Java.
It runs on an interpreter rather than compiling to machine code ahead of time, which is why it's often the first language recommended to beginners.
Example: What is Python?
# Python: readable, near-English syntax
name = "Alex"
print("Hello,", name)
Why Learn Python?
Python's clean syntax and huge ecosystem of ready-made libraries mean you spend more time solving your actual problem and less time fighting the language itself.
That combination of gentle learning curve and serious production power is why it stays one of the most in-demand skills for both beginners and professional engineers.
Example: Why Learn Python?
# Import the statistics module for calculations like mean()
import statistics
scores = [88, 92, 79, 95] # list of four test scores
print(statistics.mean(scores)) # compute and print the average score
How Python Works
Because Python is interpreted, the interpreter reads and executes your source file one statement at a time instead of compiling the whole program into a binary first.
This makes the edit-run-fix loop very fast for experimentation, though it also means Python programs typically run slower than compiled languages for raw number-crunching.
Example: How Python Works
print("Step 1")
print("Step 2")
print("Step 3")
# Each line runs immediately, in order -- no separate compile step
Applications of Python
Python powers an unusually wide range of real work: Django and Flask for web backends, NumPy/Pandas/scikit-learn for data science and machine learning, requests and BeautifulSoup for scraping and automation, and boto3 or similar SDKs for cloud infrastructure scripting.
Example: Applications of Python
# Django/Flask: web backends
# NumPy, Pandas, scikit-learn: data science & ML
# requests, BeautifulSoup: scraping & automation
# boto3: cloud infrastructure scripting
print("Python powers web, data science, scraping, and cloud tools")
Benefits of Python
Python ships official installers for Windows, macOS, and Linux, so the same script generally runs unmodified across platforms.
Combined with one of the largest open-source communities of any language, that portability means answers, packages, and tutorials for almost any problem are just a search away.
Example: Benefits of Python
import platform # module to get info about the operating system
print("Running on:", platform.system()) # print the current OS name
print("Same script runs on Windows, macOS, and Linux") # message emphasizing cross-platform support
- Typing
pythonand expecting an interactive result from a.pyfile: runningpythonalone opens the REPL, while a script needspython hello.py. - Calling the language 'compiled only' or assuming Python 2 code such as
print "hi"still works, when Python 3 requiresprint("hi"). - Installing Python but never ticking 'Add python.exe to PATH' on Windows, so the
pythoncommand is not found in the terminal.
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: