Introduction to Python: Basics, Syntax and Your First Programs
Start learning Python from scratch: what Python is, how it runs, core syntax, your first programs, and the mistakes to avoid in week one.
Chapter 1 of 20 · Beginner · 20 min read · Free
The hook
"I expected programming to feel like solving a math exam in a foreign language. Python felt like writing a to-do list — and somehow the computer actually did it."
Most people expect their first programming language to be brutal: confusing symbols, cryptic errors, rules that seem arbitrary. Honestly? A lot of languages are exactly that.
Python was designed to be the exception. Its creator, Guido van Rossum, had one explicit goal: make code that a human being would actually enjoy reading. The result is a language that looks almost like plain English — but runs on computers around the world, powering everything from Netflix recommendations to NASA spacecraft.
This chapter teaches you what Python is, how it works under the hood, and how to write your first real programs — line by line, with working code you can run today.
Your first Python program
Let's not wait for theory. Here is a real Python program:
print("Hello, World!")
print("Welcome to Python!")
Output:
Hello, World!
Welcome to Python!
That's it. Two lines. No setup rituals, no boilerplate, no semicolons required. You told the computer to display text — and it did.
print() is a built-in Python function — a pre-written instruction that Python already knows how to execute. You will use it constantly. Every time you want Python to show you something, print() is how you ask.
Try it yourself: change "Hello, World!" to your own name, run it again, and notice how that tiny edit is exactly how every programmer thinks — change code, observe output, repeat.
Now try this:
print("My name is Alex")
print("I am learning Python")
print("This is Day 1")
You can call print() as many times as you want. Each call outputs one line. Python executes instructions from top to bottom, one line at a time. That order matters, and you will use it throughout this course.
What is Python? A clear explanation
Python is a general-purpose, high-level programming language first released by Guido van Rossum in 1991. General-purpose means Python is not built for one niche: the same language you use for a beginner script is used for web apps, data analysis, machine learning, automation, and tooling. High-level means Python handles memory, CPU details, and many low-level concerns so you can write instructions closer to human language and still get working programs.
Compare printing text in C++ versus Python:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
The same task in Python:
print("Hello, World!")
One line versus seven. This is not a toy comparison — it reflects a design philosophy. Python prioritizes readability so a new programmer can infer intent before memorizing symbols.
Because Python is general-purpose, the skills you build here transfer across domains. You might start by printing messages and taking keyboard input, then graduate to reading CSV files, building a small API, or automating a boring spreadsheet workflow — without switching languages. That continuity matters for motivation: you are not learning a disposable “learner language” that disappears when you get serious.
Because Python is high-level, you can focus on problem solving first. Later in your career you may learn more about memory layout, concurrency models, or performance tuning — but you do not need that mental stack on day one to write correct programs and understand what each line does.
How Python actually executes your code
Python is an interpreted language: when you run a file, Python reads your code line by line and executes each instruction as it goes. There is no separate compile step before execution the way you have with many C++ or Java workflows.
For beginners, interpreted execution is a huge advantage. When something goes wrong, Python stops at the line that caused the problem and reports a specific error type and message — you always know where to look first.
| Topic | Compiled (examples: C++, Java) | Interpreted (Python) |
|---|---|---|
| How it runs | Entire program translated to machine code first, then executed | Reads and executes line by line |
| Error discovery | Often at compile time before running | At runtime when that line is reached |
| Typical speed | Faster raw execution for many workloads | Fast enough for most learning and product tasks |
| Feedback loop | Compile → fix → recompile → run | Edit → run → fix immediately |
Example: Python stops on the typo and never reaches the final line.
print("Line 1 runs fine")
print("Line 2 runs fine")
primt("Line 3 has a typo") # Python stops here
print("Line 4 never runs")
You should see a NameError pointing at primt. That immediate, specific feedback is why Python is one of the fastest languages to learn to program in.
Python syntax: the rules that make Python readable
Syntax is the set of rules that define valid Python. Break syntax and Python cannot run your code. Learn these rules once and they become automatic.
Rule 1: indentation is not optional
In many languages indentation is style. In Python, indentation defines blocks. The standard is four spaces per level (VS Code usually maps Tab to spaces for you). You will rely on this heavily from Day 8 (conditionals) onward.
# Correct indentation
if 5 > 3:
print("Five is greater")
print("This runs too")
print("This is outside the if")
# Wrong indentation — raises IndentationError
if 5 > 3:
print("Missing indent causes an error")
Rule 2: Python is case-sensitive
print and Print are different names. name and Name are different variables. This trips beginners constantly in week one.
print("This works")
Print("This fails") # NameError
Rule 3: comments explain your code
A comment is text Python ignores. It exists for humans — including future you. Prefer comments that explain why, not only what.
# This is a single-line comment
print("Hello") # inline comment
Rule 4: strings need quotes
Text values must be wrapped in matching quotes — single or double — consistently.
print("Double quotes work")
print('Single quotes work too')
# Mixing opening and closing quote styles causes a SyntaxError
Why Python works the way it does
Beginner-friendly features are deliberate. Python favors readable keywords (for, in, if, not, and, or) over dense punctuation, which lowers the cognitive load between reading a concept and typing it.
The feedback loop is fast: edit, run, see output in seconds. Mistakes are normal — Python tells you where and what, which shortens the learning cycle compared to long compile failures.
Python is free to use, and the ecosystem on PyPI is enormous. The same language scales from small scripts to large production systems, so you are not learning a “toy” that you must throw away later.
Where Python is used in the real world
Web development: Django and Flask power real products and microservices at serious scale. Data science: Pandas, NumPy, and Matplotlib are standard tools wherever decisions are data-driven. Machine learning: TensorFlow and PyTorch use Python as their primary interface for research and production. Automation: DevOps and cloud workflows rely heavily on Python scripts. Science: NASA, CERN, and university labs use Python for analysis and simulation — including workflows behind major scientific results.
You do not need to pick a specialty today. The fundamentals in this course — variables, control flow, functions, data structures, and classes — show up in every specialization.
If you are wondering whether Python is “only for beginners,” look at production reality: large teams ship serious systems in Python because maintainability and team velocity often beat raw micro-optimizations. You can start simple and still end up in the same ecosystem as advanced practitioners — which is exactly what this roadmap is designed for.
Setting up Python: everything you need
Step 1 — download Python. Visit python.org/downloads. Install a current Python 3 release. On Windows, check Add Python to PATH during installation so your terminal can find python.
Step 2 — verify installation. Open a terminal and run:
python --version
You should see a Python 3.x line. If you do, Python is installed.
Step 3 — install VS Code. Download VS Code, then install Microsoft’s Python extension for syntax highlighting, diagnostics, and one-click runs.
Step 4 — first file. Create hello.py, add:
print("Python is running")
print("Setup complete")
Run it with python hello.py or the VS Code Run button. If you see the output, you are ready for the rest of the course.
Four mistakes every Python beginner makes in week one
Mistake 1 — forgetting quotes around strings. print(Hello) looks like a variable named Hello. Use print("Hello").
Mistake 2 — wrong indentation. If you see IndentationError, check that the body of a block is indented consistently (usually four spaces).
Mistake 3 — mixing `=` and `==`. = stores a value; == compares values. You will practice both in Day 3 (operators) and Day 8 (conditionals).
Mistake 4 — `print` without parentheses. That is Python 2 syntax. This course uses Python 3, which requires print("Hello").
Practice: introduction to Python exercises
Reading is not the same as writing. These drills only use ideas from this chapter: print(), basic syntax, and comments — no variables or loops yet.
Exercise 1 — personal introduction. Print your name, your city, and one thing you want to learn. Use three separate print() calls.
Exercise 2 — fix the broken code. This snippet has three syntax errors. Find and fix them all:
Print("Hello")
print(Welcome to Python)
print("My name is Alex'
Exercise 3 — your first comment. Write a program that prints three lines. Add a comment above each print() explaining what it prints.
Exercise 4 — predict the output. Before running, write what you think will print. Then run and compare:
print("First")
print("Third")
print("Second")
When you are ready for a full bank of beginner programs with solutions, continue here: See all Basic Python exercises with solutions.
What comes next: Day 2 — variables and data types
You now know what Python is, how interpreted execution behaves, the core syntax rules, and how to run a first file. The next step is variables — how Python remembers information so programs can reuse values instead of repeating literals everywhere.
Day 2 covers: creating variables, naming rules, core types (integers, floats, strings, booleans), how Python infers types, and converting values between types when parsing user input.
Continue here when you are ready: Continue to Day 2: Variables and Data Types.
Chapter navigation
Use the Previous and Next links below this lesson (real <a href> links for crawling). For the first chapter, Previous returns you to the Python course overview at /courses/python.
Frequently asked questions: Introduction to Python
Is Python a good first programming language?
Python is consistently recommended as the best first language for most learners. Its syntax is readable, error messages are specific, and setup takes less than ten minutes. The same fundamentals you learn in Python—variables, loops, functions, and classes—transfer directly to other languages you learn later.
What is the difference between Python 2 and Python 3?
Python 2 reached end-of-life in January 2020 and is no longer supported. Python 3 is the current version and the only version you should learn. This course uses Python 3 exclusively. If you encounter old tutorials using print without parentheses, they are Python 2 and that syntax will not work in Python 3.
Do I need to install Python to follow this course?
You need Python installed to run code on your own machine, which we strongly recommend—installation usually takes under ten minutes using the steps in the Setup section. Alternatively, you can use an online editor such as Replit or the Python.org shell to run examples without installing anything.
How long does it take to finish the Introduction to Python chapter?
Most learners finish the reading in about twenty minutes and the practice exercises in another ten to fifteen. If a concept feels unclear, re-reading that section beats moving forward with gaps.
What should I do if I get an error in my first program?
Read the error message carefully—Python reports the line number and error type. The most common first-week issues are NameError (missing quotes or wrong name), IndentationError (spacing), and SyntaxError (structure or typos). See the Common Beginner Mistakes section on this page for concrete fixes.
What comes after the Introduction chapter?
Day 2 covers Variables and Data Types—how Python stores and works with information. The full course has twenty chapters from basics through web development, APIs, and database operations.