当前位置:首页>python>Python编程零基础学习

Python编程零基础学习

  • 2026-07-02 13:12:55
Python编程零基础学习



从零到一:写给完全新手的Python温柔入门指南

亲爱的读者,你好。

也许你对“编程”这个词既好奇又敬畏,也许你在网上看到别人用Python做出了酷炫的数据图表、自动化工具,甚至人工智能应用,心里暗暗想:“我能不能也试试?”

答案是:你完全可以。

这篇文章是为了从未写过一行代码的你准备的。我会用最慢的语速、最通俗的比喻、最详细的示例,带你一步步走进Python的世界。在这个过程中,你不必害怕犯错——每一个报错都是最好的老师,每一个困惑都是进步的阶梯。

准备好了吗?深呼吸,我们一起开始。

---

第一部分:为什么是Python?——给编程小白的第一个答案

在正式学习之前,我想先回答你心中可能存在的疑问:“编程语言那么多,为什么我要学Python?”

1.1 Python的三大温柔之处

第一,它像英语一样自然。
来看看对比:

```python
# 其他语言(C++)的写法
#include <iostream>
using namespace std;
int main() {
cout << "Hello World" << endl;
return 0;
}

# Python的写法
print("Hello World")
```

是不是Python更接近你日常说话的方式?print就是“打印”,"Hello World"就是你要打印的内容。几乎不需要额外解释。

第二,它不需要你提前知道很多东西。
有些语言要求你声明变量类型、管理内存、处理指针——这些概念光听就头疼。Python说:“你只管写,剩下的交给我。”

第三,它能做的事情超乎想象。

· 用5行代码爬取一个网页上的所有图片
· 用10行代码自动整理你电脑里的文件
· 用20行代码做一个猜数字小游戏
· 用100行代码训练一个能识别手写数字的AI

Python就像一个万能工具箱,而你现在即将学会如何使用最基础的那几件工具。

1.2 一个让你更有信心的数据

根据2024年的编程语言排行榜,Python是初学者首选入门语言,超过60%的美国顶尖大学计算机科学专业将Python作为第一门教学语言。这意味着,如果你从Python开始,你走的是全世界最主流、最成熟的学习路径。

---

第二部分:搭建你的第一个编程环境

在开始写代码之前,我们需要先准备好“纸和笔”。别担心,这个过程比安装一个手机App复杂不了多少。

2.1 下载Python

1. 打开浏览器,访问Python官网:python.org
2. 把鼠标移到顶部的“Downloads”菜单,它会自动识别你的操作系统(Windows/Mac/Linux),显示一个黄色的下载按钮
3. 点击这个黄色按钮,下载安装程序

💡 一个小提示:如果你用的是Windows电脑,下载文件名中会带有windows字样;如果是Mac,会带有macos字样。

2.2 安装Python(关键步骤)

Windows用户请特别注意这一步:

双击下载的安装文件后,你会看到一个窗口。在窗口底部有一个复选框,上面写着:

✅ Add Python to PATH

请务必勾选它! 如果不勾选,后续使用会非常麻烦。很多初学者卡在这一步,不是因为笨,而是因为没注意到这个小框。

勾选之后,点击“Install Now”,等待进度条走完即可。

Mac用户:双击安装包,按照提示一路“继续”就好。

2.3 验证安装是否成功

安装完成后,我们来验证一下。

· Windows:按键盘上的Win + R键,输入cmd,回车。在弹出的黑窗口中输入:

```
python --version
```

如果看到类似Python 3.12.0这样的字样(数字可能不同),说明安装成功。

· Mac:打开“启动台” -> “终端”,输入同样的命令。

如果显示“不是内部或外部命令”或“command not found”,说明上一步的“Add to PATH”没有勾选。别慌,重新运行安装程序,这次记得勾上就行。

2.4 选择你的写作工具

Python装好后,你可以在上面那个黑窗口里写代码,但那样体验不太好。我推荐你用下面任意一种方式:

方案A(最简单):IDLE
Python自带了一个简易编辑器叫IDLE。你可以在开始菜单或应用程序文件夹里找到它,双击打开,直接写代码。适合前两周的学习。

方案B(更好的体验):VS Code
免费、轻量、功能强大。去code.visualstudio.com下载安装,然后在左侧扩展图标里搜索“Python”并安装官方插件。这是很多专业程序员都在用的工具。

方案C(零配置):网页版
如果你暂时不想安装任何东西,可以访问replit.com或jupyter.org/try,直接在浏览器里写Python代码。零配置,打开即用。

我建议你第一周先用IDLE,等熟悉了基本语法再换成VS Code。

2.5 你的第一行代码:Hello World

打开IDLE,你会看到一个>>>提示符。在它后面输入:

```python
print("Hello, World!")
```

然后按回车。如果你看到屏幕上输出了Hello, World!,恭喜你!你已经成功运行了第一段Python程序。

这个看似简单的仪式,其实是编程世界里最重要的传统——用“你好,世界”向这门语言打招呼。

---

第三部分:变量——给数据起一个名字

想象你有一个盒子,里面可以放任何东西。你给盒子上贴一个标签,写上“我的玩具”。以后你想找玩具的时候,只需要看这个标签,不用打开盒子看里面是什么。

在Python里,变量就是那个标签。

3.1 第一次创建变量

让我们直接动手:

```python
name = "小明"
age = 18
height = 1.75
is_student = True
```

这里发生了什么?

· name、age、height、is_student 是变量名(你贴的标签)
· = 是赋值符号(把右边的值放进左边的盒子里)
· "小明"、18、1.75、True 是值(盒子里的内容)

之后,你想用这些值的时候,直接用变量名就行:

```python
print(name) # 输出:小明
print(age) # 输出:18
```

3.2 变量的数据类型

Python世界里有几种基本的“东西”,就像现实世界里有数字、文字、真/假一样。

类型名称 中文 示例 说明
int 整数 42、-5、0 没有小数点的数字
float 浮点数 3.14、-0.5、2.0 有小数的数字
str 字符串 "你好"、'hello' 用引号包裹的文字
bool 布尔值 True、False 只有两个值:真和假

为什么要区分类型?因为不同类型能做不同的事。数字可以做加减乘除,字符串可以做拼接和查找,布尔值可以做逻辑判断。

实验一下:

```python
# 数字可以做数学运算
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.333...
print(a // b) # 3(整除,只取整数部分)
print(a % b) # 1(取余数)

# 字符串可以拼接
first = "Hello"
second = "World"
print(first + " " + second) # Hello World

# 字符串可以重复
print("Ha" * 3) # HaHaHa
```

3.3 变量名的命名规则

给变量起名字,就像给自己的孩子起名字一样,有一些基本规则:

必须遵守的规则(否则Python会报错):

1. 只能包含字母、数字、下划线_(不能有空格、横线、@等特殊符号)
2. 不能以数字开头(1st不行,first1可以)
3. 不能是Python的关键字(比如if、for、while这些有特殊含义的词)

约定俗成的好习惯(建议遵守):

1. 用有意义的英文单词:price比p好,user_age比ua好
2. 多个单词用下划线连接:student_name(而不是studentname或studentName)
3. 常量用大写:MAX_SIZE = 100
4. 保持一致的风格

```python
# 好的变量名示例
first_name = "张"
last_name = "三"
total_price = 99.9
max_attempts = 5

# 不好的变量名示例
a = "张" # 含义不明
first name = "张" # 有空格,语法错误
2nd_try = 3 # 数字开头,语法错误
if = 10 # if是关键字,语法错误
```

3.4 变量的重新赋值

变量不是一成不变的。你可以随时改变盒子里的东西:

```python
score = 60
print(score) # 60

score = 85 # 重新赋值
print(score) # 85

score = score + 10 # 先计算右边,再把结果赋给左边
print(score) # 95
```

最后一行score = score + 10一开始可能有点难理解。还记得数学里的等号吗?数学里等号表示“相等”,但编程里的=表示“把右边的值放进左边的变量”。所以这句话的意思是:先取出score当前的值(85),加上10得到95,再把95放回score里。

这种写法太常见了,Python提供了简写方式:

```python
score = 85
score += 10 # 等价于 score = score + 10
score -= 5 # 等价于 score = score - 5
score *= 2 # 等价于 score = score * 2
score /= 3 # 等价于 score = score / 3
```

3.5 输入:让程序和你互动

程序不能总是处理固定的数据,它需要从用户那里获取信息。input()函数就是做这个的:

```python
name = input("请输入你的名字:")
print("你好," + name + "!欢迎来到Python世界。")
```

当你运行这段代码时,程序会停下来,等待你输入一些文字并按下回车。你输入的内容会被赋值给name变量。

需要注意的是,input()永远返回字符串类型。如果你需要数字,必须手动转换:

```python
age_str = input("请输入你的年龄:") # age_str是字符串,比如"18"
age = int(age_str) # 转换成整数18

# 更简洁的写法
age = int(input("请输入你的年龄:"))

height = float(input("请输入身高(米):")) # 浮点数用float()
```

⚠️ 常见错误:如果你输入了"十八"而不是"18",int()会报错,因为它不认识中文数字。这时候程序会中断。后面我们会学到如何处理这种错误。

3.6 小节练习

试着写一个程序,完成以下功能:

1. 询问用户的名字
2. 询问用户的出生年份
3. 计算用户的年龄(假设今年是2026年)
4. 输出:"XXX,你好!你今年XX岁。"

答案(建议先自己写,再看答案):

```python
name = input("请输入你的名字:")
birth_year = int(input("请输入你的出生年份:"))
age = 2026 - birth_year
print(f"{name},你好!你今年{age}岁。")
```

---

第四部分:print()的多种用法——如何优雅地输出

print()是你学习Python过程中使用最频繁的函数。它远比你想象的强大。

4.1 基本用法

```python
# 打印一个值
print("Hello")

# 打印多个值,用逗号分隔,默认会加一个空格
print("Hello", "World", "!") # Hello World !

# 打印数字和字符串混合
print("年龄是", 18, "岁") # 年龄是 18 岁
```

4.2 格式化输出:让输出更可控

方法一:逗号拼接(前面用过,但不够灵活)

方法二:字符串拼接(用+号)

```python
name = "小红"
score = 95
print("学生" + name + "的分数是" + str(score))
# 注意:数字必须用str()转换成字符串才能拼接
```

方法三:f-string(强烈推荐,Python 3.6+支持)
在字符串前面加一个f,然后在字符串内部用{}包裹变量名,Python会自动替换成变量的值。

```python
name = "小红"
score = 95
print(f"学生{name}的分数是{score}") # 学生小红的分数是95

# 还可以在{}里做简单的运算
price = 100
discount = 0.8
print(f"折后价格:{price * discount}元") # 折后价格:80.0元

# 还可以控制小数位数:{变量:.2f} 表示保留两位小数
pi = 3.1415926
print(f"圆周率约等于{pi:.2f}") # 圆周率约等于3.14
```

方法四:format()方法(旧式,了解即可)

```python
print("{}的年龄是{}".format("小明", 18)) # 小明的年龄是18
```

4.3 控制print的结尾和分隔符

默认情况下,print()每次输出后会换行。如果你不想换行,可以用end参数:

```python
print("Hello", end="")
print("World")
# 输出:HelloWorld(没有换行)

print("Loading", end="...")
print("Done")
# 输出:Loading...Done

# 也可以自定义分隔符(默认是空格)
print("苹果", "香蕉", "橙子", sep=", ")
# 输出:苹果, 香蕉, 橙子

# 组合使用
print("A", "B", "C", sep="-", end="END\n")
# 输出:A-B-CEND
```

---

第五部分:条件判断——让程序自己做决定

现实世界中,我们经常根据不同的情况做不同的事:“如果下雨,我就带伞;否则,就不带。”

Python里的if语句,就是让程序拥有这种“做决定”的能力。

5.1 if语句的基本结构

```python
if 条件:
条件成立时执行的代码
```

注意:if后面的条件不需要加括号,但后面必须加冒号:,并且要执行的代码必须缩进(通常是4个空格)。

```python
weather = "rain"

if weather == "rain":
print("带上伞出门")

print("这句话无论天气如何都会执行")
```

千万不要忘记缩进! Python用缩进来表示哪些代码属于if。如果你写:

```python
if weather == "rain":
print("带上伞出门") # 没有缩进,报错!
```

5.2 比较运算符——怎么写条件

条件就是那些结果为“真”或“假”的表达式。用于比较的符号叫比较运算符:

运算符 含义 示例 结果
== 等于(注意是两个等号) 5 == 5 True
!= 不等于 5 != 3 True
> 大于 5 > 3 True
< 小于 5 < 3 False
>= 大于等于 5 >= 5 True
<= 小于等于 5 <= 3 False

⚠️ 一个常见错误:把==(比较)写成=(赋值)。if score = 100:会报错,因为赋值语句不能作为条件。

5.3 if-else:二选一

当你需要“如果……否则……”的逻辑时,用else:

```python
score = 75

if score >= 60:
print("及格了,恭喜!")
else:
print("不及格,下次努力")
```

5.4 if-elif-else:多选一

当有多个分支时,用elif(else if的缩写):

```python
score = 85

if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 60:
print("及格")
else:
print("不及格")
```

程序从上到下依次检查条件,一旦某个条件满足,就执行对应的代码块,然后跳出整个判断结构,不会再检查后面的elif。

5.5 逻辑运算符:组合多个条件

有时候一个条件不够,需要同时满足多个条件,或者满足其中之一。

运算符 含义 示例 说明
and 且 age >= 18 and age <= 60 两个条件都为True才为True
or 或 day == "周六" or day == "周日" 至少一个为True即为True
not 非 not is_raining 取反

```python
age = 25
has_license = True

# 且:两个条件都要满足
if age >= 18 and has_license:
print("可以开车")

# 或:满足任意一个即可
day = "周六"
if day == "周六" or day == "周日":
print("今天是周末")

# 非:取反
is_weekend = False
if not is_weekend:
print("今天是工作日")
```

5.6 嵌套判断

判断里面还可以再放判断:

```python
age = 20
has_ticket = True

if age >= 18:
if has_ticket:
print("检票通过,请入场")
else:
print("请先买票")
else:
print("未成年不能入场")
```

不过嵌套太多会让代码难以阅读。很多时候可以用and来简化上面的代码:

```python
if age >= 18 and has_ticket:
print("检票通过,请入场")
elif age >= 18 and not has_ticket:
print("请先买票")
else:
print("未成年不能入场")
```

5.7 实战案例:BMI分类器

让我们把知识整合起来,写一个完整的程序:

```python
# 获取用户输入
height = float(input("请输入你的身高(米):"))
weight = float(input("请输入你的体重(公斤):"))

# 计算BMI
bmi = weight / (height ** 2) # ** 表示乘方,height ** 2 是身高的平方

# 分类判断
print(f"你的BMI指数是:{bmi:.1f}")

if bmi < 18.5:
print("体重过轻")
elif bmi < 24:
print("正常范围")
elif bmi < 28:
print("超重")
else:
print("肥胖")
```

---

第六部分:循环——让电脑帮你重复做事

世界上最无聊的事情就是重复做同一件事。幸运的是,电脑最擅长的就是重复。

如果你想让程序做一件事100遍,不需要写100行代码,只需要一个循环。

6.1 for循环:遍历已知的范围

for循环适用于你知道要循环多少次,或者要遍历一组已知的数据。

基本语法:

```python
for 变量 in 可迭代对象:
重复执行的代码
```

例子1:循环5次

```python
for i in range(5):
print(f"这是第{i}次循环")
```

输出:

```
这是第0次循环
这是第1次循环
这是第2次循环
这是第3次循环
这是第4次循环
```

range(5)生成了0、1、2、3、4这5个数字。注意从0开始,到4结束,不包括5。这是编程世界里的常见习惯。

range()的三种用法:

```python
# range(stop): 从0到stop-1
for i in range(5): # 0,1,2,3,4

# range(start, stop): 从start到stop-1
for i in range(2, 6): # 2,3,4,5

# range(start, stop, step): 指定步长
for i in range(1, 10, 2): # 1,3,5,7,9(每次增加2)
```

例子2:遍历列表

```python
fruits = ["苹果", "香蕉", "橙子", "葡萄"]

for fruit in fruits:
print(f"我喜欢吃{fruit}")
```

例子3:遍历字符串

```python
message = "Hello"

for char in message:
print(char)
# 输出:H e l l o(每个字母单独一行)
```

6.2 while循环:直到条件不满足

while循环适用于你不知道要循环多少次,只知道什么时候停止。

```python
while 条件:
重复执行的代码
```

只要条件为True,循环就会一直执行。所以一定要确保条件最终会变为False,否则就成了无限循环,程序永远停不下来。

例子:倒计时

```python
countdown = 5

while countdown > 0:
print(countdown)
countdown -= 1 # 每次减1,最终会变成0

print("发射!")
```

例子:猜数字游戏(直到猜对为止)

```python
secret = 7
guess = 0

while guess != secret:
guess = int(input("猜一个1-10之间的数字:"))

if guess < secret:
print("太小了")
elif guess > secret:
print("太大了")

print("恭喜你猜对了!")
```

6.3 break:提前跳出循环

有时候你想在条件满足之前就结束循环,可以用break:

```python
# 这个程序会一直问,直到用户输入"退出"
while True: # 无限循环
command = input("输入指令(输入'退出'结束):")

if command == "退出":
print("程序结束")
break # 跳出循环

print(f"执行命令:{command}")
```

6.4 continue:跳过本次循环

continue会跳过本次循环中剩余的代码,直接进入下一次循环:

```python
# 打印1到10之间的奇数
for i in range(1, 11):
if i % 2 == 0: # 如果是偶数
continue # 跳过,不打印
print(i)
```

6.5 循环的嵌套

循环里面还可以放循环,这叫嵌套循环:

```python
# 打印乘法口诀表
for i in range(1, 10):
for j in range(1, i + 1):
print(f"{j}×{i}={i*j}", end="\t")
print() # 换行
```

这段代码可能看着有点复杂,但你可以试着运行一下,看看输出是什么。

6.6 实战案例:计算平均值

```python
# 输入5个数字,计算平均值
total = 0

for i in range(5):
num = float(input(f"请输入第{i+1}个数字:"))
total += num

average = total / 5
print(f"总分为:{total},平均分为:{average:.2f}")
```

---

第七部分:列表——批量管理数据

当你有10个数字、20个名字、100个成绩时,你会创建100个变量吗?当然不会。

列表就是Python用来批量存储数据的方式——它像一个可以扩展的抽屉柜,每个抽屉有一个编号(索引),你可以往里面放任何类型的东西。

7.1 创建列表

列表用方括号[]表示,元素之间用逗号分隔:

```python
# 各种类型的列表
numbers = [1, 2, 3, 4, 5]
names = ["小明", "小红", "小刚"]
mixed = [1, "hello", 3.14, True] # 列表可以混合类型
empty = [] # 空列表
```

7.2 访问元素:索引

列表中的每个元素都有位置编号,从0开始:

```python
fruits = ["苹果", "香蕉", "橙子", "葡萄"]

print(fruits[0]) # 第一个:苹果
print(fruits[1]) # 第二个:香蕉
print(fruits[2]) # 第三个:橙子
print(fruits[3]) # 第四个:葡萄
```

负索引:从末尾开始数,-1是最后一个:

```python
print(fruits[-1]) # 葡萄
print(fruits[-2]) # 橙子
```

索引范围:[start:end]获取子列表(包含start,不包含end):

```python
print(fruits[1:3]) # ['香蕉', '橙子'] 索引1和2,不包括3
print(fruits[:2]) # ['苹果', '香蕉'] 从开头到索引2之前
print(fruits[2:]) # ['橙子', '葡萄'] 从索引2到结束
print(fruits[:]) # 整个列表的副本
```

7.3 修改和添加元素

```python
fruits = ["苹果", "香蕉"]

# 修改指定索引的元素
fruits[1] = "草莓"
print(fruits) # ['苹果', '草莓']

# 在末尾添加
fruits.append("橙子")
print(fruits) # ['苹果', '草莓', '橙子']

# 在指定位置插入
fruits.insert(1, "芒果")
print(fruits) # ['苹果', '芒果', '草莓', '橙子']

# 扩展列表(合并另一个列表)
fruits.extend(["葡萄", "西瓜"])
print(fruits) # ['苹果', '芒果', '草莓', '橙子', '葡萄', '西瓜']
```

7.4 删除元素

```python
fruits = ["苹果", "香蕉", "橙子", "苹果", "葡萄"]

# 删除指定索引的元素(默认删除最后一个)
fruits.pop() # 删除并返回最后一个元素(葡萄)
fruits.pop(1) # 删除索引1的元素(香蕉)

# 删除第一个匹配的值
fruits.remove("苹果") # 只删除第一个苹果

# 删除指定索引的元素(更通用的方法)
del fruits[0] # 删除第一个元素

# 清空整个列表
fruits.clear()

# 查看某个值第一次出现的索引
index = fruits.index("橙子")
```

7.5 列表的常用操作

```python
numbers = [3, 1, 4, 1, 5, 9, 2]

# 长度(元素个数)
print(len(numbers)) # 7

# 最大值、最小值、求和(对数字列表)
print(max(numbers)) # 9
print(min(numbers)) # 1
print(sum(numbers)) # 25

# 排序(会改变原列表)
numbers.sort() # 升序:[1, 1, 2, 3, 4, 5, 9]
numbers.sort(reverse=True) # 降序

# 反转
numbers.reverse()

# 统计某个值出现的次数
print(numbers.count(1)) # 2
```

7.6 遍历列表

```python
scores = [85, 92, 78, 90, 88]

# 方法1:直接遍历元素
for score in scores:
print(score)

# 方法2:遍历索引(需要同时知道索引和值时)
for i in range(len(scores)):
print(f"第{i+1}个学生的分数是{scores[i]}")

# 方法3:同时获取索引和值(最优雅)
for i, score in enumerate(scores):
print(f"第{i+1}个学生的分数是{score}")
```

7.7 列表推导式(进阶但很有用)

如果你想从一个列表生成另一个列表,可以用非常简洁的写法:

```python
# 传统写法
numbers = [1, 2, 3, 4, 5]
squares = []
for n in numbers:
squares.append(n ** 2)
print(squares) # [1, 4, 9, 16, 25]

# 列表推导式(一行搞定)
squares = [n ** 2 for n in numbers]
print(squares) # [1, 4, 9, 16, 25]

# 加上条件:只保留偶数
even_squares = [n ** 2 for n in numbers if n % 2 == 0]
print(even_squares) # [4, 16]
```

7.8 实战案例:学生成绩管理系统

```python
# 存储学生姓名和成绩
students = []
scores = []

while True:
print("\n=== 学生成绩管理系统 ===")
print("1. 添加学生")
print("2. 查看所有学生")
print("3. 计算平均分")
print("4. 找出最高分")
print("5. 退出")

choice = input("请选择操作:")

if choice == "1":
name = input("学生姓名:")
score = float(input("成绩:"))
students.append(name)
scores.append(score)
print(f"已添加学生:{name},成绩:{score}")

elif choice == "2":
if len(students) == 0:
print("暂无学生")
else:
print("\n所有学生:")
for i in range(len(students)):
print(f"{students[i]}:{scores[i]}分")

elif choice == "3":
if len(scores) > 0:
avg = sum(scores) / len(scores)
print(f"全班平均分:{avg:.1f}")
else:
print("暂无数据")

elif choice == "4":
if len(scores) > 0:
max_score = max(scores)
max_index = scores.index(max_score)
print(f"最高分:{students[max_index]},{max_score}分")
else:
print("暂无数据")

elif choice == "5":
print("程序退出")
break

else:
print("无效选择")
```

---

第八部分:元组和字典——更多存储方式

8.1 元组:不可变的列表

元组和列表很像,但创建之后不能修改(不能增、删、改)。用圆括号()表示。

```python
# 创建元组
colors = ("红", "绿", "蓝")
single = (5,) # 只有一个元素的元组,注意逗号不能省
empty = () # 空元组

# 访问元素(和列表一样)
print(colors[0]) # 红

# 尝试修改会报错
# colors[0] = "黄" # 错误!

# 元组可以解包
red, green, blue = colors
print(red) # 红

# 什么时候用元组?
# - 保证数据不会被意外修改
# - 作为字典的键(列表不行)
# - 函数返回多个值时
```

8.2 字典:键值对

如果说列表是有编号的抽屉(0号、1号、2号……),那么字典就是有标签的抽屉(“姓名”、“年龄”、“城市”……)。字典用花括号{}表示。

```python
# 创建一个字典
student = {
"name": "小明",
"age": 18,
"city": "北京",
"score": 95
}

# 通过键访问值
print(student["name"]) # 小明
print(student["age"]) # 18

# 添加或修改(注意中括号)
student["gender"] = "男" # 添加新键值对
student["score"] = 98 # 修改已有键的值

# 删除
del student["city"]

# 安全访问(避免KeyError)
print(student.get("city")) # None(因为已删除)
print(student.get("city", "未知")) # 未知(可以指定默认值)
```

字典的常用操作:

```python
person = {"name": "小红", "age": 20, "job": "学生"}

# 获取所有键
print(person.keys()) # dict_keys(['name', 'age', 'job'])

# 获取所有值
print(person.values()) # dict_values(['小红', 20, '学生'])

# 获取所有键值对
print(person.items()) # dict_items([('name', '小红'), ('age', 20), ('job', '学生')])

# 遍历字典
for key in person:
print(f"{key}: {person[key]}")

# 更优雅的遍历
for key, value in person.items():
print(f"{key}: {value}")
```

实战:简单的电话簿

```python
phonebook = {}

while True:
print("\n=== 电话簿 ===")
print("1. 添加联系人")
print("2. 查找联系人")
print("3. 删除联系人")
print("4. 显示所有联系人")
print("5. 退出")

choice = input("请选择:")

if choice == "1":
name = input("姓名:")
phone = input("电话:")
phonebook[name] = phone
print(f"已添加{name}")

elif choice == "2":
name = input("要查找的姓名:")
if name in phonebook:
print(f"{name}的电话是:{phonebook[name]}")
else:
print("未找到该联系人")

elif choice == "3":
name = input("要删除的姓名:")
if name in phonebook:
del phonebook[name]
print("已删除")
else:
print("未找到")

elif choice == "4":
if phonebook:
for name, phone in phonebook.items():
print(f"{name}: {phone}")
else:
print("电话簿为空")

elif choice == "5":
break
```

---

第九部分:函数——封装你的代码

你有没有发现,刚才写的程序里,同样的功能(比如打印菜单)可能会出现在多个地方?如果每次都要重写一遍,不仅麻烦,而且一旦需要修改,要改很多处。

函数就是用来解决这个问题的——把一段代码打包,起一个名字,以后想用的时候直接“叫”它的名字。

9.1 定义和调用函数

用def关键字定义函数:

```python
# 定义一个简单的函数
def say_hello():
print("Hello!")
print("欢迎来到Python世界")

# 调用函数
say_hello()
```

9.2 参数:给函数传递信息

```python
# 带参数的函数
def greet(name):
print(f"你好,{name}!")

greet("小明") # 你好,小明!
greet("小红") # 你好,小红!
```

9.3 返回值:让函数给结果

```python
def add(a, b):
result = a + b
return result # 返回结果

sum = add(3, 5)
print(sum) # 8

# return会立即结束函数
def check_age(age):
if age < 18:
return "未成年"
return "成年" # 只有年龄>=18才会执行这一行
```

9.4 默认参数和关键字参数

```python
# 默认参数:如果不传值,就使用默认值
def greet(name, greeting="你好"):
return f"{greeting},{name}"

print(greet("小明")) # 你好,小明
print(greet("小红", "晚上好")) # 晚上好,小红

# 关键字参数:调用时指定参数名,顺序可以乱
print(greet(greeting="早上好", name="小刚")) # 早上好,小刚
```

9.5 变量的作用域

函数内部定义的变量,外面无法访问:

```python
def my_func():
x = 10 # 局部变量
print(x)

my_func()
# print(x) # 错误!x不存在于函数外部

# 全局变量可以在函数内读取,但修改需要global声明
y = 20 # 全局变量

def read_global():
print(y) # 可以读取

def modify_global():
global y # 声明要修改全局变量
y = 30

modify_global()
print(y) # 30
```

9.6 实战案例:重构成绩管理系统

用函数把之前的成绩管理系统改得更清晰:

```python
# 全局数据
students = []
scores = []

def show_menu():
print("\n=== 学生成绩管理系统 ===")
print("1. 添加学生")
print("2. 查看所有")
print("3. 计算平均分")
print("4. 找出最高分")
print("5. 退出")

def add_student():
name = input("学生姓名:")
score = float(input("成绩:"))
students.append(name)
scores.append(score)
print(f"已添加:{name},{score}分")

def show_all():
if not students:
print("暂无学生")
return
print("\n学生列表:")
for i in range(len(students)):
print(f"{students[i]}:{scores[i]}分")

def show_average():
if scores:
avg = sum(scores) / len(scores)
print(f"平均分:{avg:.1f}")
else:
print("暂无数据")

def show_highest():
if scores:
max_score = max(scores)
idx = scores.index(max_score)
print(f"最高分:{students[idx]},{max_score}分")
else:
print("暂无数据")

# 主程序
while True:
show_menu()
choice = input("请选择:")

if choice == "1":
add_student()
elif choice == "2":
show_all()
elif choice == "3":
show_average()
elif choice == "4":
show_highest()
elif choice == "5":
print("感谢使用,再见!")
break
else:
print("无效选择")
```

---

第十部分:错误处理——让程序更健壮

你的程序一定会遇到错误:用户输入了“abc”而程序期望数字、想要删除一个不存在的文件、网络请求超时……

学会处理错误,是写出“专业”程序的重要一步。

10.1 try-except结构

```python
# 正常的除法
def divide(a, b):
return a / b

# 但如果b=0,程序会崩溃
# divide(10, 0) # ZeroDivisionError

# 使用try-except捕获错误
def safe_divide(a, b):
try:
result = a / b
return result
except ZeroDivisionError:
print("错误:除数不能为0")
return None

print(safe_divide(10, 2)) # 5.0
print(safe_divide(10, 0)) # 错误:除数不能为0
```

10.2 处理多种错误

```python
def get_number():
try:
value = int(input("请输入一个整数:"))
return value
except ValueError:
print("错误:请输入有效的整数")
return None

# 可以同时处理多种错误
def safe_operation():
try:
a = int(input("a: "))
b = int(input("b: "))
result = a / b
print(f"结果:{result}")
except ValueError:
print("输入的不是有效数字")
except ZeroDivisionError:
print("除数不能为0")
except Exception as e:
print(f"发生了未知错误:{e}")
```

10.3 实战:健壮的输入函数

```python
def get_positive_int(prompt):
"""反复询问,直到用户输入一个正整数"""
while True:
try:
value = int(input(prompt))
if value > 0:
return value
else:
print("请输入正数")
except ValueError:
print("请输入有效的整数")

age = get_positive_int("请输入你的年龄:")
print(f"年龄是:{age}")
```

---

总结:你的Python旅程才刚刚开始

亲爱的读者,感谢你一路读到这里。

我们从安装Python开始,学习了变量、条件判断、循环、列表、字典、函数,一直到错误处理。这趟旅程,你已经掌握了Python编程的核心基础——这些知识足以让你写出很多实用的小程序了。

但更重要的是,我希望你已经感受到了编程的本质:编程不是背诵语法,而是用逻辑解决问题。每当你遇到一个报错,那不是失败,而是电脑在帮你纠正思路;每当你写出一个能运行的程序,那种成就感是独一无二的。

我想对你说几句心里话

作为一个同样从零基础走过来的人,我深知自学编程的不易。你可能会遇到“为什么我的代码就是不对”的深夜,可能会被某个概念卡住好几天,可能会怀疑自己“是不是不适合学编程”。

请你相信:这些感受,每一个程序员都经历过。 这不是能力的证明,而是成长必经的路。遇到困难时,不要硬扛——去搜索、去Stack Overflow提问、去和同样在学习的朋友讨论。编程是一门“可以随时查阅”的技能,没有任何程序员能记住所有语法,他们只是知道“如何找到答案”。

接下来你可以往哪里走

根据你的兴趣,这里有几条清晰的路径:

· 如果你对数据感兴趣:学习pandas(数据处理)、matplotlib(图表绘制)、numpy(数值计算)
· 如果你想自动化办公:学习openpyxl(操作Excel)、python-docx(操作Word)、pyautogui(控制鼠标键盘)
· 如果你想做网站:学习Flask(轻量级Web框架)或Django(全能型框架)
· 如果你想获取网络数据:学习requests(发送HTTP请求)、BeautifulSoup(解析HTML)
· 如果你想进入人工智能领域:学习scikit-learn(机器学习)、PyTorch或TensorFlow(深度学习)

最后的温柔叮嘱

编程不是一场短跑,而是一场马拉松。每天写15分钟,比周末写8小时更有效。 不要追求一次性写出完美的代码,先让它“能用”,再让它“好用”。

如果这篇文章中有任何地方让你感到困惑,请记住:不是你不聪明,而是我可以用更好的方式解释。 编程里的每一个概念,都可以用更生活化的比喻、更多的例子来讲清楚。如果你卡住了,欢迎带着具体问题去搜索、去问、去实践。

最后,请允许我用Python社群最流行的一句话作为结尾:

“Python的禅意”说:简单优于复杂,明了优于隐晦。

你已经迈出了最难的第一步——开始。剩下的路,一步一步走,总能到达。

祝你编程愉快,保持好奇,保持耐心。期待有一天,你用Python写出属于自己的作品。

现在,去写你的下一行代码吧。 🐍

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 08:28:08 HTTP/2.0 GET : https://f.mffb.com.cn/a/490888.html
  2. 运行时间 : 0.103356s [ 吞吐率:9.68req/s ] 内存消耗:4,881.43kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=22c0506421b68178b1933b7804bfd164
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000530s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000773s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000290s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000341s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000759s ]
  6. SELECT * FROM `set` [ RunTime:0.000246s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000700s ]
  8. SELECT * FROM `article` WHERE `id` = 490888 LIMIT 1 [ RunTime:0.006080s ]
  9. UPDATE `article` SET `lasttime` = 1783038488 WHERE `id` = 490888 [ RunTime:0.001916s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000313s ]
  11. SELECT * FROM `article` WHERE `id` < 490888 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000651s ]
  12. SELECT * FROM `article` WHERE `id` > 490888 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000515s ]
  13. SELECT * FROM `article` WHERE `id` < 490888 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001102s ]
  14. SELECT * FROM `article` WHERE `id` < 490888 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003194s ]
  15. SELECT * FROM `article` WHERE `id` < 490888 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.015856s ]
0.104959s