Intro to Python
The world's most popular beginner language. Clean syntax, endless possibilities.
The world's most popular beginner language. Clean syntax, endless possibilities.
In 1991, a Dutch programmer named Guido van Rossum released a new programming language. He named it after his favorite comedy show: Monty Python's Flying Circus. His goal was simple: make programming readable, fun, and accessible to everyone.
Guido van Rossum releases the first version from the Netherlands. It already has classes, functions, and exception handling.
List comprehensions and garbage collection arrive. The community grows rapidly as Python becomes a serious tool.
A major redesign focused on consistency and removing old patterns. The version everyone uses today.
The most popular programming language in the world, used by Google, NASA, Instagram, Spotify, and millions of developers.
Python is now the #1 language for beginners and the top choice for data science, AI, and machine learning. It is taught in more universities than any other language and has one of the largest developer communities in the world.
Every programmer's journey starts with the same ritual: making the computer say "Hello, World!" In Python, it takes just one line.
print() is a built-in function that displays text on the screen. You pass it a value inside the parentheses, and Python outputs it. That is the entire program. No setup, no boilerplate, no semicolons.
Compare that to other languages:
| Language | Hello, World! |
|---|---|
| Python | print("Hello, World!") |
| Java | System.out.println("Hello, World!"); |
| C++ | std::cout << "Hello, World!" << std::endl; |
| Rust | println!("Hello, World!"); |
Now let's try variables and f-strings (formatted strings):
In Python, you create a variable just by giving it a name and a value. No let, var, or int keyword needed. The f-string (notice the f before the quote) lets you embed variables directly inside a string using curly braces {}.
Try it in the Python REPL (Read-Eval-Print Loop). The >>> prompt means Python is waiting for your input:
"ha" * 3 gives you "hahaha". Python is full of small surprises like this that make it feel playful and intuitive.
Python's lists store collections of items, and for loops let you do something with each one. The syntax is so clean it almost reads like English.
Indentation matters in Python. The indented line under the for statement is the loop body. Python uses indentation (usually 4 spaces) instead of curly braces {} to define code blocks. This forces clean, readable code.
You can also use range() to loop a specific number of times:
Python also has list comprehensions, a powerful shorthand for building lists:
for x in collection pattern is one of Python's most loved features. Unlike C-style loops (for (int i = 0; i < n; i++)), Python's version says exactly what it means: "for each item in this collection, do something."
Functions let you wrap up a block of code, give it a name, and reuse it. In Python, you define a function with the def keyword.
def defines a function. name is a parameter, a placeholder for the value you pass in when you call the function. return sends a value back to wherever the function was called from.
Functions can take multiple parameters and have default values:
Here is a more practical example, a function that processes a list:
Python is not the fastest language or the most compact. What makes it special is a combination of readability, versatility, and an enormous ecosystem of tools and libraries.
Often called "executable pseudocode." Python reads almost like English, making it easy to learn and easy to maintain.
Over 400,000 packages on PyPI (the Python Package Index). Install anything with pip install.
The #1 language for machine learning, data analysis, and AI research. Libraries like NumPy, Pandas, and TensorFlow power it all.
Frameworks like Django and Flask power major websites including Instagram, Pinterest, and Dropbox.
Automate file management, web scraping, emails, spreadsheets, and more. Python is the Swiss Army knife of scripting.
Millions of developers, thousands of tutorials, and a welcoming community that helps beginners get started.
Dynamic typing means you do not declare variable types. Python figures them out automatically. Write x = 42 and Python knows it is an integer. Write x = "hello" and now it is a string. This makes prototyping fast, though large projects sometimes add type hints for clarity.
Here are some of the most popular Python libraries and what they do:
Data analysis
Math and arrays
Machine learning
Charts and plots
Web framework
Web scraping
Game development
Image processing
import this in the Python REPL. The most famous line: "There should be one, and preferably only one, obvious way to do it."
Ready to write some Python? Here is a quick reference to get you started. Open the terminal and follow along.
apt install python3
nano hello.py
python3 hello.py
python3
2 + 2 or print("hi")
exit() or Ctrl+D
Here is a mini-project to try. Create a file called quiz.py and paste this in:
This program asks the user a question and checks their answer.
Run it with python3 quiz.py and answer the questions. Then try adding your own questions to the quiz.
time module. Can you make it pick random questions from a bigger list? (Hint: import random and use random.sample().)
You've explored the language that powers AI, web apps, data science, automation, and so much more. Python's readable syntax and massive ecosystem make it the perfect first language.
Python uses indentation and clean syntax so code reads almost like English.
Python ships with a huge standard library, and pip gives you access to 400,000+ packages.
From web apps to machine learning to automation, Python handles it all.
Python is the #1 language taught in universities and the top choice for first-time programmers.
Put your new knowledge into practice!