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.

💡 Tip: "High-level" means it's closer to human language, not that it's "superior." The opposite is "low-level" languages (like assembly), which deal directly with hardware and are hard to read and write.

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:

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:

💡 Tip: Learn Python 3 directly. The latest stable version is Python 3.13 (released in 2025). Don't touch Python 2 unless you're maintaining a decade-old legacy system.


2. Installing Python

On Windows

  1. Open your browser and go to https://www.python.org/downloads/
  2. Click the yellow "Download Python 3.x.x" button (choose the latest version)
  3. Run the installer, make sure to check "Add Python to PATH" at the bottom
  4. Click "Install Now" and wait for completion
  5. Verify: open Command Prompt (Win + R, type cmd), enter python --version

On macOS

macOS comes with Python 3, but it may not be the latest version. Install via Homebrew:

BASH
brew install python

Verify:

BASH
python3 --version

On Linux (Ubuntu example)

Most Linux distributions come with Python 3 pre-installed. If not, use the package manager:

BASH
sudo apt update
sudo apt install python3

Verify:

BASH
python3 --version
💡 Tip: On Windows, type 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:

BASH
python

You'll see a prompt like:

TEXT
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:

PYTHON
print("Hello, World!")

Press Enter and you'll see:

TEXT
Hello, World!
⚠️ Note: 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:

  1. Create a new file named hello.py (.py is the Python extension)
  2. Open it with Notepad or VS Code, enter:
PYTHON
print("Hello, World!")
  1. Save the file and run it in the terminal:
BASH
python hello.py

Output:

TEXT
Hello, World!

Open terminal → type command → see output. That's the standard workflow.

💡 Tip: VS Code offers a great experience for Python — syntax highlighting, error hints, and more. If you haven't installed it, get it from code.visualstudio.com and install the Python extension.


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.

PYTHON
# 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)
▶ Try it Yourself

Output:

TEXT
Hello everyone, I'm learning Python!
First line
Second line
Third line
====================
Welcome to the world of Python!
====================

A few new things:

Example 2: Python as a Calculator (Difficulty ⭐)

Python can perform various math operations. Open interactive mode and type:

PYTHON
>>> 3 + 5
8
>>> 10 - 4
6
>>> 7 * 8
56
>>> 15 / 4
3.75
▶ Try it Yourself

If you write a script file calculator.py:

PYTHON
# 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:

TEXT
3 + 5 = 8
10 - 4 = 6
7 × 8 = 56
15 ÷ 4 = 3.75
💡 Tip: 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().

PYTHON
# 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!")
▶ Try it Yourself

Sample run:

TEXT
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!
⚠️ Note: 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


❓ FAQ

Q Which is better — Python, Java, or C++?
A None is "better"; each excels in different areas. Python's strengths are quick learning curve and high development speed, ideal for data analysis, AI, and automation. Java dominates enterprise backends. C++ is closer to hardware with maximum performance, suitable for game engines and operating systems. As a first language, Python is the most beginner-friendly. ⚠️ Q: I installed Python but typing 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

  1. Basic (Difficulty ⭐): Use print() to output your favorite movie quote or poem. Try using \n for line breaks and "=" * 30 for a separator.

  2. 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."

  3. Challenge (Difficulty ⭐⭐⭐): Use print(), input(), and int() 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.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏