Skip to content

Python Overview

什么 Python 是, 哪里它 运行, and 为什么它 是 one 的大多数 popular languages for 初学者 and professionals alike.

你将学到

  • 什么 Python 是 and 为什么它 是 popular
  • 哪里 Python 运行 (scripts, 服务器, 数据 science, AI)
  • Python's 设计 philosophy: readability and simplicity
  • 如何 运行你的首先 Python program

概念讲解

什么是 Python?

Python is a high-level, general-purpose programming language created by Guido van Rossum in 1991. It is famous for its clean, readable syntax that almost looks like plain English — which is why it is the most recommended first language for beginners.

Where Python Runs

Python is everywhere:

  • Web servers — frameworks like Django and Flask power back-ends for Instagram, Spotify, and Reddit.
  • Data science & AI — libraries like NumPy, Pandas, and PyTorch make Python the dominant language for machine learning and data analysis.
  • Automation & scripting — sysadmins and DevOps engineers use Python to automate repetitive tasks.
  • Desktop & mobile — tools like PyQt and Kivy build cross-platform apps.
  • Education — Python is the most common teaching language in universities and coding bootcamps.

Why Python Is Popular

  1. Readable syntax — code looks like English. No curly braces or semicolons required.
  2. Batteries included — the standard library is huge: math, file I/O, networking, dates, and more come built-in.
  3. Beginner-friendly — you can write useful programs in your first hour.
  4. Huge ecosystem — over 400,000 packages on PyPI (the Python Package Index).
  5. Versatile — the same language works for a quick script, a web server, or a machine learning model.

The Design Philosophy

Python's design is guided by 20 principles called The Zen of Python. You can read them by running 导入 这个 in a Python shell. The most famous:

  • *Beautiful is better than ugly.*
  • *Explicit is better than implicit.*
  • *Readability counts.*
  • *Simple is better than complex.*

This philosophy drives every decision in the language — Python prioritizes developer readability and clarity over brevity or cleverness.

Running Python

You can run Python in several ways:

  • Interactive shell — type python (or python3) in your terminal to open the REPL.
  • Script file — save code in a .py file and run python myscript.py.
  • Online — platforms like Google Colab and Replit let you run Python in the browser without installing anything.

Python uses indentation (whitespace) instead of braces to define code blocks. This forces consistent formatting and is one of the first things newcomers notice.

示例代码

              # Python's classic first program
print("Hello, World!")

# Python reads like English — this is valid, readable code
name = "Ada"
age = 25
print(f"{name} is {age} years old")

# The standard library is huge — math comes built-in
import math
print("Pi is approximately", math.pi)
print("The square root of 16 is", math.sqrt(16))

# The Zen of Python — run this to see Python's design principles
import this

# Python uses indentation for code blocks (no braces!)
if age >= 18:
    print("You are an adult")
else:
    print("You are a minor")
            

这个 shows hello 世界, f-字符串, 构建-in math 模块, Zen 的 Python, and indentation-based 块. 运行它 使用 python3 overview.py or 粘贴它 到 Python REPL.

动手试一试

  • JSON Formatter

    Python dicts look 如 JSON — 练习格式化它们.

  • Regex Tester

    Python's re 模块 uses 相同 regex 语法 — 测试模式 live.

常见错误

错误写法

Mixing tabs and 空间 for indentation

正确做法

Python uses indentation 到定义块. Mixing tabs and 空间 causes SyntaxError. 配置你的 editor 到 use 4 空间 (PEP 8 标准) and 从不 mix 它们.

错误写法

Forgetting colon at 端的 如果, for, 虽然, and def 行

正确做法

Python 需要 colon (:) at 端的 语句那个 introduce 块, 如如果 x:, for i in 范围(3):, and def func():. Forgetting 它是 大多数常见 SyntaxError for 初学者.

相关代码片段

相关速查表

练习 Python Overview

3 个练习

练习 Python Overview

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误