Introduction to Python
Learn what Python is and set up your development environment
Learning Objectives
- Understand what Python is and why it's popular
- Install Python on your computer
- Write and run your first Python program
- Use the Python REPL for interactive coding
What is Python?
Python is a high-level, interpreted programming language created by Guido van Rossum and first released in 1991. It’s known for its clean syntax and readability, making it an excellent choice for beginners.
Why Learn Python?
Python is one of the most popular programming languages in the world. Here’s why:
Python’s Key Features
| Feature | Description |
|---|---|
| Interpreted | Code runs line by line, no compilation needed |
| Dynamically Typed | No need to declare variable types |
| High-Level | Abstracts complex details from the programmer |
| Object-Oriented | Supports classes and objects |
| Cross-Platform | Runs on Windows, macOS, and Linux |
| Extensive Libraries | Thousands of packages available |
Setting Up Your Environment
Let’s get Python installed on your computer.
Step 1: Download Python
- Go to python.org
- Click the “Download Python” button
- The website will detect your operating system automatically
Step 2: Verify Installation
Open your terminal (Command Prompt on Windows, Terminal on macOS/Linux) and type:
|
|
You should see something like:
Python 3.12.0
python3 --version instead. On some systems, Python 3 is accessed with the python3 command.Your First Python Program
Let’s write the classic “Hello, World!” program.
Using the Interactive Shell (REPL)
The REPL (Read-Eval-Print Loop) lets you run Python code interactively:
- Open your terminal
- Type
python(orpython3) and press Enter - You’ll see the Python prompt
>>>
Now type:
|
|
Press Enter, and you’ll see:
Hello, World!
Congratulations! You’ve just run your first Python code!
Creating a Python File
For longer programs, we write code in files with the .py extension.
- Create a new file called
hello.py - Add this code:
|
|
- Run it from the terminal:
|
|
Understanding the Code
Let’s break down what we wrote:
print()is a function - it performs an action (displaying text)- Text inside quotes is called a string
- Lines starting with
#are comments - notes for humans that Python ignores
The Python REPL
The REPL is perfect for experimenting with Python:
|
|
Useful REPL Commands
| Command | Description |
|---|---|
help() |
Access Python’s help system |
exit() |
Exit the REPL |
dir() |
List available names/functions |
type(x) |
Check the type of x |
Choosing a Code Editor
While you can write Python in any text editor, these make coding easier:
- VS Code (Recommended) - Free, powerful, lots of extensions
- PyCharm - Professional Python IDE
- Sublime Text - Fast and lightweight
- IDLE - Comes with Python, good for beginners
Summary
Today you learned:
- Python is a versatile, beginner-friendly language
- How to install Python on your computer
- How to write and run Python code
- How to use the Python REPL
Next Steps
Tomorrow, we’ll dive into variables and data types - the building blocks of any Python program.
Now, complete the quiz below to test your knowledge and unlock Day 2!
Quiz
Complete this quiz with a minimum score of 80% to mark Day 1 as complete.
Discussion
Have questions or want to discuss this lesson? Join the conversation below!