Meet Python
Just as learning to drive starts with the steering wheel, accelerator, and brake, learning to code starts with understanding your tools. Python is a powerful yet beginner-friendly programming language — this lesson introduces you to it.
1. What Is Python
Python is a high-level programming language created by Dutch programmer Guido van Rossum and first released in 1991. Its name comes from the British comedy group Monty Python, not the snake.
Python's design philosophy emphasizes code readability — code written in Python is easy to understand, even for non-programmers. Its syntax is clean and expressive; the same feature often requires only one-third to one-fifth the lines of code compared to C++ or Java.
What Can Python Do
Python has an incredibly wide range of applications:
| Area | Typical Uses | Common Tools/Frameworks |
|---|---|---|
| Web Development | Backend, APIs | Django, Flask, FastAPI |
| Data Analysis | Excel, CSV, databases | pandas, NumPy |
| Artificial Intelligence | Machine learning, deep learning | TensorFlow, PyTorch, scikit-learn |
| Automation | File processing, web scraping, email | requests, BeautifulSoup, Selenium |
| Desktop Apps | GUI tools | tkinter, PyQt |
| Game Development | Simple 2D games | Pygame |
Interpreted vs Compiled Languages
Understanding this helps you grasp how Python works:
- Compiled languages (C, C++, Go): Code is first translated into machine-executable binary by a compiler, then run. Like writing a letter → translating it to English → handing it to the recipient.
- Interpreted languages (Python, JavaScript): Code is translated and executed line-by-line by an interpreter. Like speaking a sentence → a simultaneous interpreter translates it on the spot.
Python is interpreted, which means you can test as you go, making development fast and ideal for beginners to quickly try out ideas.
Python 2 vs Python 3
If you search for Python tutorials online, you might encounter both Python 2 and Python 3:
- Python 2 is the old version, officially discontinued in 2020.
- Python 3 is the current mainstream version. All new projects should use Python 3.
2. Installing Python
On Windows
- Open your browser and go to https://www.python.org/downloads/
- Click the yellow "Download Python 3.x.x" button (choose the latest version)
- Run the installer, make sure to check "Add Python to PATH" at the bottom
- Click "Install Now" and wait for completion
- Verify: open Command Prompt (
Win + R, typecmd), enterpython --version
On macOS
macOS comes with Python 3, but it may not be the latest version. Install via Homebrew:
brew install python
Verify:
python3 --version
On Linux (Ubuntu example)
Most Linux distributions come with Python 3 pre-installed. If not, use the package manager:
sudo apt update
sudo apt install python3
Verify:
python3 --version
python; on macOS/Linux, you may need python3. This is due to historical reasons. We'll use python throughout.
3. Running Your First Python Program
Python has two modes: interactive mode and script file mode.
Interactive Mode (REPL)
Interactive mode is like having a conversation with Python — you type a line, and it responds immediately.
Open a terminal and type:
python
You'll see a prompt like:
Python 3.13.0 (main, Oct 7 2025, 10:00:00)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> means Python is waiting for your command. Try typing:
print("Hello, World!")
Press Enter and you'll see:
Hello, World!
print() is a built-in Python function that outputs content to the screen. The content inside the parentheses is what gets displayed. We'll use it frequently.
Exit interactive mode: type exit() or press Ctrl + Z (Windows) / Ctrl + D (macOS/Linux).
Script File Mode
Writing code in a saved file is the proper way to program:
- Create a new file named
hello.py(.pyis the Python extension) - Open it with Notepad or VS Code, enter:
print("Hello, World!")
- Save the file and run it in the terminal:
python hello.py
Output:
Hello, World!
Open terminal → type command → see output. That's the standard workflow.
4. Examples
Example 1: Print a Self-Introduction (Difficulty ⭐)
A simple program that outputs a few lines. Don't worry about understanding everything — just get a feel for it.
# Print a line of text
print("Hello everyone, I'm learning Python!")
# Print multiple lines using \n for line breaks
print("First line\nSecond line\nThird line")
# Print a separator line for readability
print("=" * 20)
print("Welcome to the world of Python!")
print("=" * 20)
Output:
Hello everyone, I'm learning Python!
First line
Second line
Third line
====================
Welcome to the world of Python!
====================
A few new things:
\nis an escape character that represents a newline, like pressing Enter in Word."=" * 20repeats the equals sign 20 times, creating a 20-character separator. Python is smart enough to know what multiplying a string by a number means.
Example 2: Python as a Calculator (Difficulty ⭐)
Python can perform various math operations. Open interactive mode and type:
>>> 3 + 5
8
>>> 10 - 4
6
>>> 7 * 8
56
>>> 15 / 4
3.75
If you write a script file calculator.py:
# Simple math with Python
print("3 + 5 =", 3 + 5)
print("10 - 4 =", 10 - 4)
print("7 × 8 =", 7 * 8)
print("15 ÷ 4 =", 15 / 4)
Output:
3 + 5 = 8
10 - 4 = 6
7 × 8 = 56
15 ÷ 4 = 3.75
print() can take multiple values separated by commas. Python automatically adds a space between them. "3 + 5 =" is a string, while 3 + 5 is a math expression that Python evaluates first.
Example 3: A Simple Interactive Program (Difficulty ⭐⭐)
This program talks to you using input() (to get user input) and print().
# Get user input and greet them
# input() displays a prompt and waits for user input
# The input is stored in the variable 'name'
name = input("Hi, what's your name? ")
# Use an f-string to embed the name in the output
# The f prefix means it's a formatted string; {name} is replaced with the actual input
print(f"Welcome, {name}! Python is fun — let's learn together.")
# Ask for age; input() returns a string, int() converts it to an integer
age = int(input("How old are you? "))
# Do a simple calculation
print(f"In 5 years, you'll be {age + 5} years old — by then you'll be a Python pro!")
Sample run:
Hi, what's your name? Xiao Ming
Welcome, Xiao Ming! Python is fun — let's learn together.
How old are you? 18
In 5 years, you'll be 23 years old — by then you'll be a Python pro!
input() always returns a string. Even if you type a number, it's stored as text. We use int() to convert it to an integer before doing math like age + 5. Trying "18" + 5 would cause an error because you can't add a string and a number. We'll cover this in more detail later.
Common Use Cases
- Automate file processing: Merge thousands of Excel files into one — doing it manually takes a full day, but a few lines of Python can do it in 10 seconds.
- Web scraping: Automatically fetch data from websites — weather forecasts, product prices, news headlines — and save them locally.
- Build web backends: Many popular sites (Instagram, Pinterest, Spotify) use Python for their backend.
❓ FAQ
python says "'python' is not recognized"? A: This is the most common installation issue — you forgot to check "Add Python to PATH." PATH is the system's address book for finding executables. Fix: uninstall Python and reinstall, making sure to check that option. Or manually add Python's path (e.g., C:\Python313\ and C:\Python313\Scripts\) to your system environment variables.
Q: Can I use Notepad to write Python, or do I need VS Code? A: Notepad works, but it's like using a power drill as a hammer — possible, but not pleasant. VS Code is free and helps with: syntax highlighting (colors show if you're writing correctly), autocomplete (less typing), real-time error hints, and an integrated terminal. Recommended for beginners.
Q: Do I need to be good at English to learn Python? A: No, but you do need to recognize basic English words. Python keywords (like if, for, while, import) are English words, and function names are mostly English (like print, input, len). You don't need to be fluent — you'll memorize them through practice. Logical thinking matters more; language is just a tool.📖 Summary
- Python is a high-level interpreted programming language emphasizing code readability, suitable for everything from web development to AI
- Remember to check "Add Python to PATH" during installation
- Two modes: interactive (
>>>prompt) for quick testing, script files (.py) for formal development print()outputs content,input()gets user input,int()converts strings to integers
📝 Exercises
-
Basic (Difficulty ⭐): Use
print()to output your favorite movie quote or poem. Try using\nfor line breaks and"=" * 30for a separator. -
Intermediate (Difficulty ⭐⭐): Write a program that asks for the user's name and city, then outputs a welcome message containing both. Example:
"Hello, Xiao Ming! Welcome from Beijing to learn Python." -
Challenge (Difficulty ⭐⭐⭐): Use
print(),input(), andint()to build an "age calculator": ask the user for their birth year, then calculate and output their current age. Hint: You'll need to write the current year in your code.



