Chapter 1 of 11
~13 minPython Basics
Python is a high-level, interpreted, object-oriented language prized for readable syntax and a huge standard library, which is why it shows up everywhere from scripting to web backends to data science.
What Python Is, and Why It Reads the Way It Does
Python was designed around the idea that code is read far more often than it is written, so the language favors clear, minimal syntax over cleverness. There are no curly braces or semicolons - indentation itself defines which lines belong to which block, which forces a consistent visual structure onto every Python program by construction rather than by convention.
It is also dynamically typed and garbage-collected, meaning you never declare a variable's type up front and never manually free memory - the interpreter figures out types at runtime and reclaims memory once nothing references it anymore. That combination of traits is a big part of why Python is often recommended as a first language, while still being capable enough to run production systems at large companies.
A first Python program
print("Hello, Python!")
print(type("Hello, Python!"))Interpreted vs. Compiled Languages
An interpreted language like Python executes source code line by line through an interpreter, with no separate build step - you run the file and it starts executing immediately. A compiled language like C or Java instead translates the entire program into machine code (or bytecode) ahead of time, which usually means faster execution but a slower edit-run cycle since every change has to be rebuilt first.
In practice, Python occupies a middle ground: the interpreter first compiles your source into an intermediate bytecode (the .pyc files you may have seen in a __pycache__ folder), then that bytecode is executed by the Python virtual machine. You never have to trigger this step yourself, which is why Python still feels purely interpreted from a developer's point of view.
PEP 8 and Writing Readable Code
PEP 8 is Python's official style guide, covering things like using snake_case for variable and function names, four spaces per indentation level, a sensible maximum line length, and consistent spacing around operators. None of it is enforced by the interpreter - code that violates PEP 8 still runs fine - but following it keeps a codebase consistent and much easier for a team (or your future self) to read.
Non-PEP-8 style vs. PEP 8 style
def CalcSum(a,b):return a+b
def calc_sum(a, b):
return a + b
print(calc_sum(2, 3))Variables and Dynamic Typing
A variable in Python is just a name bound to a value in memory - you create one simply by assigning to it, with no type declaration required. The type is inferred from whatever value is assigned, and because Python is dynamically typed, the same variable name can be reassigned to a value of a completely different type later in the program.
This flexibility is convenient, but it also means a typo or a mistaken reassignment will not be caught until the program actually runs into a mismatch - there is no compiler checking your types ahead of time the way there is in a statically typed language.
The same variable name holding different types over time
age = 25
print(age, type(age))
age = "twenty-five"
print(age, type(age))Coding Challenge
Write a script that stores your age as an integer and prints its value and type, then reassigns that same variable to a greeting string that includes the word "years old" and prints its value and type again, demonstrating Python's dynamic typing.
Answer every question below to mark this chapter as complete.
Quiz Yourself
Score: 0/51. What best describes Python as a language?
2. What is the key practical difference between an interpreted language and a compiled one?
3. What does PEP 8 govern?
4. Why can the same Python variable be reassigned from an integer to a string?
5. Where does Python actually produce bytecode, and who triggers that step?