Introduction to Python
Updated 7 min read Aimerscrew
What is Python, and why does everyone seem to be learning it? Python is a programming language: a way of writing instructions that a computer can follow. It's famous for being easy to read, quick to learn and powerful enough to run some of the biggest apps in the world. In this lesson, you'll find out what Python is, what people build with it, and why it's such a great first language.
🌍 Real-life example
Imagine writing a recipe for a friend: "Boil water. Add pasta. Wait 10 minutes." A program is the same idea, but the reader is a computer. Some programming languages make you write that recipe in strict, wordy legal language. Python lets you write it in short, clear sentences that both you and the computer understand.
What is Python?
Python is a high-level, general-purpose programming language. Let's unpack those words:
- Programming language: a set of words and rules for giving instructions to a computer.
- High-level: it's close to human language. Python handles the low-level details, like managing the computer's memory, so you can focus on your idea.
- General-purpose: it isn't limited to one job. The same language can build a website, crunch numbers or control a robot.
Python is also interpreted, which means a program called the Python interpreter reads your code and runs it straight away, without a separate build step. You'll see exactly how that works in How Python Runs Your Code.
Here's a complete Python program. It's just one line:
print("Hello, world!")
Hello, world!
print() is a built-in instruction that shows text on the screen. No setup, no extra lines, no boilerplate (repeated code you must write every time).
Who created Python, and why is it called Python?
Python was created by Dutch programmer Guido van Rossum and first released in 1991. Despite the snake logo, the name comes from the British comedy show Monty Python's Flying Circus. Guido wanted a name that was short, a little playful and easy to remember.
Today, Python is free and open source. Anyone can download it, use it for any project (even commercial ones) and look at how it's built. It runs on Windows, macOS and Linux.
What can you build with Python?
Because Python is general-purpose, it shows up almost everywhere:
- Websites and web apps: frameworks like Django and Flask power the "back end" (the server side) of many sites.
- Data analysis: turning spreadsheets of sales figures or sports statistics into charts and answers.
- Artificial intelligence (AI) and machine learning: most AI research and many chatbots are built with Python tools.
- Automation: small scripts that rename hundreds of files, fill in forms or send reminder emails for you.
- Games and fun projects: simple 2D games, quizzes and programs for tiny computers like the Raspberry Pi.
Who uses Python?
Python isn't just a teaching language. It runs real products used by millions of people every day:
| Organization | What it uses Python for |
|---|---|
| Its web back end runs on Django, a Python framework. | |
| Netflix | Data analysis, recommendations and internal tools. |
| NASA | Scientific calculations and mission software tools. |
| Spotify | Data processing and back-end services. |
| Internal tools, AI research and many public libraries. |
Scientists, bankers, teachers, marketers and hobbyists use Python too. Many people who would never call themselves "programmers" write small Python scripts to save time at work.
Why do beginners love Python?
- It's readable. Python code looks like simple English, so you can often guess what it does before you've learned it.
- It needs less code. Tasks that take ten lines elsewhere often take two or three in Python.
- It gives fast feedback. You type a line, press Enter and see the result instantly.
- It has a huge community. Millions of people use Python, so answers to almost any question are easy to find.
- It comes with "batteries included". Python ships with a large standard library (ready-made code for dates, math, files and more), and you can add thousands of free packages.
Look how readable this is. Even without any Python knowledge, you can probably tell what it does:
playlist = ["Morning Run", "Rainy Day Jazz", "Road Trip"]
for song in playlist:
print("Now playing:", song)
Now playing: Morning Run
Now playing: Rainy Day Jazz
Now playing: Road Trip
How does Python compare to Java and C?
The best way to see Python's simplicity is to write the same tiny program in three languages. Each one prints Hello, world!.
Java:
public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
C:
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
Python:
print("Hello, world!")
Hello, world!
Java and C are excellent languages, but they ask you to learn words like public, static, void and #include before you can say hello. Python lets you start with the idea itself.
| Python | Java | C | |
|---|---|---|---|
| Lines for "Hello, world!" | 1 | 5 | 6 |
| Semicolons at line ends | No | Yes | Yes |
Curly braces { } for blocks | No (uses indentation) | Yes | Yes |
| Separate compile step before running | No | Yes | Yes |
📝 Note
Simpler doesn't mean weaker. Python trades a little raw speed for a lot of developer speed. For most programs, the time you save writing code matters far more than the milliseconds the computer saves running it.
Python 2 vs Python 3: which should you learn?
You may see two versions mentioned online. Python 3 was released in 2008 and fixed several design problems in Python 2. Python 2 officially reached its end of life on January 1, 2020, which means it no longer gets fixes, even for security problems.
| Python 2 (old) | Python 3 (current) | |
|---|---|---|
| Printing | print "Hi" | print("Hi") |
7 / 2 gives | 3 | 3.5 |
| Status | Retired since 2020 | Actively developed |
This tutorial uses Python 3 everywhere. If you find an old tutorial that writes print without parentheses, it's Python 2, and you should skip it.
print(7 / 2)
3.5
A first taste: a coffee order in Python
Here's a slightly bigger program. It stores a few facts about a coffee order and prints a short receipt:
drink = "Cappuccino"
price = 4
cups = 3
print("Order:", cups, "x", drink)
print("Total:", price * cups, "dollars")
Order: 3 x Cappuccino
Total: 12 dollars
Don't worry about every detail yet. You'll learn about names like drink and price in the Python variables lesson. For now, notice how little code it takes to do something useful.
Common beginner mistakes
1. Following a Python 2 tutorial
Old code like this fails in Python 3:
print "Welcome!"
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Python 3 always needs parentheses: print("Welcome!").
2. Trying to learn everything at once
Python can do web, data, AI and games, but you don't need all of that on day one. Master the basics in this tutorial first; every specialty builds on them.
3. Reading code without running it
You learn programming by doing. Type every example yourself, run it, then change something and see what happens.
💡 Tip
Spend 20 to 30 minutes a day writing code. Short, regular practice beats one long session a week.
Practice exercise
🏋️ Try it yourself
You haven't installed Python yet, so let's practice reading code. Look at the program below and predict exactly what it prints before you open the solution.
team = "Lions"
goals = 2
print("Final score")
print(team, "scored", goals + 1, "goals")
Show solution
Final score
Lions scored 3 goals
Python runs the lines from top to bottom. goals + 1 is calculated first (2 + 1 = 3), and print() puts a space between each item.
What's next?
Now you know what Python is and why it's worth learning. Next, get it running on your own computer: follow our step-by-step guide on how to install Python on Windows, macOS or Linux.
Key takeaways
- Python is a free, high-level, general-purpose programming language that reads almost like English.
- It was created by Guido van Rossum, first released in 1991, and named after Monty Python.
- People use Python for websites, data analysis, AI, automation and games.
- Companies such as Instagram, Netflix, NASA, Spotify and Google rely on Python.
- Python needs far less code than Java or C for the same task, which makes it ideal for beginners.
- Always learn Python 3. Python 2 reached its end of life in 2020.
Frequently asked questions
What is Python used for?
Python is used for building websites, analyzing data, machine learning and AI, automating repetitive tasks, scientific research and making simple games.
Is Python good for beginners?
Yes. Python has clean, readable syntax and needs very little code to get results, so it is one of the most popular first programming languages in schools and universities.
Is Python free?
Yes. Python is free and open source. You can download it from python.org and use it for personal or commercial projects without paying anything.
Should I learn Python 2 or Python 3?
Learn Python 3. Python 2 stopped receiving updates on January 1, 2020, and all modern libraries and tutorials use Python 3.
How long does it take to learn Python?
Most people learn the basics in a few weeks of regular practice. Becoming confident enough to build real projects usually takes a few months.
Is Python a compiled or interpreted language?
Python is usually called interpreted because you run code directly with the Python interpreter. Behind the scenes, it first turns your code into bytecode, which the Python Virtual Machine then runs.