1. Python Introduction
What you will learn
- What Python is and what it is used for
- Why many beginners choose it
- How a Python program runs
What is Python?
Python is a general-purpose programming language known for code that is easy to read. You write short, clear instructions, and the Python interpreter runs them one after another.
Python was created by Guido van Rossum and first released in 1991. It is free and open source, and it runs on Windows, macOS, and Linux.
A first look
Python code: hello.py
print("Hello, world!")
Output
Hello, world!
One line is a complete program. print() is a built-in function that shows text on the screen. Compare that with languages that need several lines of set-up before they can print a greeting.
What is Python used for?
- Automation and scripting: renaming files, processing spreadsheets, and repetitive tasks.
- Web back ends: frameworks such as Django and Flask build websites and APIs.
- Data and science: analysing data, charts, and research.
- Machine learning and AI: many popular libraries are written for Python.
- Teaching: its simple syntax makes it a common first language.
Python compared with what you have learned here
| Language | Runs where | Main job |
|---|---|---|
| HTML and CSS | Browser | Structure and appearance of pages |
| JavaScript | Browser (and servers) | Interactivity in pages |
| PHP | Server | Building web pages, powering WordPress |
| Python | Your computer or a server | Scripts, data, automation, web back ends, AI |
WordPress, the system behind this site, is written in PHP, not Python. You can still use Python alongside it, for example to process data or automate tasks.
How a Python program runs
- You write your code in a text file that ends in
.py. - You ask Python to run it.
- The interpreter reads the file from top to bottom and carries out each instruction.
Python also has an interactive mode, where you type a line and see the result straight away. It is ideal for trying things out, and the next lesson shows how to open it.
Python 3
This course teaches Python 3, the current and only supported major version. Older Python 2 code (for example print "hello" without brackets) no longer works in Python 3. Check python.org for the latest release.
You will not run Python in your browser on this website. You will install it on your own computer in the next lesson, which takes a few minutes.
Common mistakes
- Confusing Python with JavaScript or PHP. They have different rules.
- Following old tutorials written for Python 2.
- Expecting a
.pyfile to run by double-clicking in every case. Use the method in lesson 2. - Thinking “easy to read” means “no rules”. Python is strict about indentation, as you will see.
Exercise
Name two things Python is used for, and explain in one sentence how it differs from HTML.
Show solution
For example: automating tasks, and building the back end of a website or analysing data. HTML only describes the structure of a page and cannot run logic, while Python is a programming language that can make decisions, repeat actions, and process data.
Knowledge check
1. What file ending do Python programs use?
.py
2. Which built-in function shows text on screen?
print()
3. Which version of Python does this course teach?
Python 3.
Summary
- Python is a readable, general-purpose language used for automation, web back ends, data, and AI.
- An interpreter runs your
.pyfile from top to bottom. - You will install Python on your own computer in the next lesson.