Python Intro
Python · Getting Started
Theory
Python is a high-level, general-purpose programming language designed to be easy to read. You write instructions in plain-looking text, and the Python interpreter takes care of memory, types and other low-level details for you. That is why it is so popular for data analysis, automation scripts, web back-ends and machine learning.
When you run a file, the standard interpreter (CPython) first compiles your source code into bytecode, a compact set of low-level instructions, and then its virtual machine executes that bytecode one instruction at a time. Everything you work with, a number, a piece of text, a list, even a function, is an object stored in memory, and variables are just names pointing at those objects. Python is dynamically typed: the type belongs to the value, not to the variable name.
Why we use it
Python lets you go from idea to working code with very little ceremony. There is no type declaration or build step, the syntax reads close to English, and a huge library ecosystem (pandas, NumPy, requests and more) means common data tasks are already solved.
When to use it
Use Python for data cleaning, analysis, automation, APIs and prototyping. For very speed-critical loops over millions of numbers, lean on libraries like NumPy or pandas (written in C underneath) instead of plain Python loops.
How it works
- You write hello.py
- Interpreter reads and parses the source text
- Is the syntax valid? Yes: Compile the code into bytecode. No: Stop with a SyntaxError before anything runs.
- Python virtual machine runs bytecode instruction by instruction
- Objects are created in memory as the code runs
- Output appears, e.g. Hello, TechTown!
Syntax
print("Hello, World!")Example
print("Hello, TechTown!")Key points
- Usually called interpreted: source is compiled to bytecode, then run by the interpreter
- Dynamically typed: a variable can point to an int now and a str later
- Everything is an object, even numbers and functions
- Huge ecosystem of libraries for data work (pandas, NumPy, matplotlib)
- Free and open source
- A SyntaxError stops the whole file before the first line runs