当前位置:首页>python>Python函数完全指南:让你的代码模块化、可复用

Python函数完全指南:让你的代码模块化、可复用

  • 2026-02-10 20:28:14
Python函数完全指南:让你的代码模块化、可复用

你有没有想过,为什么优秀的代码看起来那么整洁?为什么别人能快速解决复杂问题?这背后的秘密,就藏在函数里。函数是Python编程的核心,掌握了函数,你就能写出模块化、可复用、可维护的代码。

嗨,我是你的Python学习搭子!前面我们搞定了Python的基础语法、控制流和数据类型三剑客,今天我们要解锁编程的第五个核心概念:函数

别被这个词吓到,其实它就像我们生活中的工具:锤子用来钉钉子,螺丝刀用来拧螺丝,函数就是用来完成特定任务的代码块。有了函数,你就能把复杂的问题分解成一个个小任务,让代码变得更加清晰和高效。

为什么函数这么重要?因为函数是代码的基本组成单元,没有函数,代码就像一堆乱麻。有了函数,你就能把重复的代码封装起来,只需要调用一次就能完成任务。函数还能让代码更加模块化,每个函数负责一个特定的功能,让代码更容易理解和维护。

🧠 函数:代码的基本组成单元

Python中的函数可以分为以下几类:

  1. 1. 基础函数:使用def关键字定义的普通函数
  2. 2. 匿名函数:使用lambda表达式定义的函数
  3. 3. 高阶函数:接收函数作为参数或返回函数的函数
  4. 4. 装饰器:用于增强函数功能的特殊函数

今天我们会逐一了解,保证你学完就能用!

📝 函数基础概念

什么是函数?

函数就像一个"代码加工厂":你投入原材料(参数),经过内部机器运转(函数体),最后产出成品(返回值)。

函数定义的基本结构

def函数名(参数):"""文档字符串:说明函数功能"""# 函数体:执行具体操作return 返回值

最简单的函数示例

# 示例1:无参数无返回值的函数defsay_hello():"""打印问候语"""print("Hello, Python!")say_hello()  # 调用函数# 输出:Hello, Python!# 示例2:带参数的函数defgreet(name):"""向指定的人打招呼"""returnf"Hello, {name}!"message = greet("码趣师")print(message)  # 输出:Hello, 码趣师!# 示例3:带默认参数的函数defpower(base, exponent=2):"""计算base的exponent次方"""return base ** exponentprint(power(3))  # 输出:9 (3²)print(power(33))  # 输出:27 (3³)

函数的核心优势

优势
说明
示例
代码重用
避免重复编写相同代码
计算圆面积、排序算法
模块化
将复杂系统分解为多个功能模块
用户管理、数据处理
可维护性
修改函数内部逻辑,不影响调用方
修改计算公式、优化算法
可测试性
独立测试每个函数的功能
单元测试、集成测试

📊 参数详解

参数类型全景图

defdemo_function(a, b, c=10, *args, d=20, **kwargs):"""    参数顺序示例:    a, b - 位置参数(必填)    c=10 - 默认参数    *args - 可变位置参数    d=20 - 命名关键字参数    **kwargs - 可变关键字参数    """pass

1️⃣ 位置参数(Positional Arguments)

最基础的参数形式,按顺序传递。

defdescribe_pet(animal_type, pet_name):"""描述宠物信息"""print(f"我有一只{animal_type},名字叫{pet_name}")# 正确调用describe_pet('仓鼠''哈利')  # 输出:我有一只仓鼠,名字叫哈利# 错误调用:顺序颠倒会导致逻辑错误describe_pet('哈利''仓鼠')  # 输出:我有一只哈利,名字叫仓鼠(逻辑不通)

2️⃣ 关键字参数(Keyword Arguments)

使用"键=值"格式,顺序不重要。

defcreate_user(username, age, email):"""创建用户"""print(f"用户名: {username}, 年龄: {age}, 邮箱: {email}")# 使用关键字参数,顺序可以打乱create_user(age=25, email="test@example.com", username="码趣师")# 输出:用户名: 码趣师, 年龄: 25, 邮箱: test@example.com# 混合使用:位置参数在前,关键字参数在后create_user("码趣师"25, email="test@example.com")

3️⃣ 默认参数(Default Arguments)

为参数设定默认值,调用时可省略。

defmake_pizza(size, crust="薄脆", *toppings):"""制作披萨"""print(f"\n制作一个{size}{crust}披萨,配料如下:")for topping in toppings:print(f"- {topping}")# 使用默认饼底make_pizza(12"芝士""蘑菇""青椒")# 输出:# 制作一个12寸薄脆披萨,配料如下:# - 芝士# - 蘑菇# - 青椒# 指定饼底make_pizza(12"厚底""香肠""洋葱")# 输出:# 制作一个12寸厚底披萨,配料如下:# - 香肠# - 洋葱

4️⃣ 可变位置参数(*args)

接收任意数量的位置参数,打包成元组。

defcalculate_sum(*numbers):"""计算任意多个数字的和"""    total = sum(numbers)print(f"数字: {numbers}")print(f"总和: {total}")return totalcalculate_sum(12345)# 输出:# 数字: (1, 2, 3, 4, 5)# 总和: 15calculate_sum(102030)# 输出:# 数字: (10, 20, 30)# 总和: 60

5️⃣ 可变关键字参数(**kwargs)

接收任意数量的关键字参数,打包成字典。

defbuild_profile(first, last, **user_info):"""构建用户档案"""    profile = {'first_name': first,'last_name': last    }    profile.update(user_info)return profileuser = build_profile('码趣师''Python',    age=25,    city='北京',    occupation='程序员',    skills=['Python''AI''Web开发'])print(user)# 输出:# {# 'first_name': '码趣师',# 'last_name': 'Python',# 'age': 25,# 'city': '北京',# 'occupation': '程序员',# 'skills': ['Python', 'AI', 'Web开发']# }

6️⃣ 命名关键字参数

限制参数名,必须使用关键字形式传递。

defregister_user(username, *, age, email):"""注册用户,age和email必须用关键字传递"""print(f"用户名: {username}, 年龄: {age}, 邮箱: {email}")# 正确调用register_user("码趣师", age=25, email="test@example.com")# 输出:用户名: 码趣师, 年龄: 25, 邮箱: test@example.com# 错误调用:age和email必须用关键字# register_user("码趣师", 25, "test@example.com")  # 报错

参数顺序总结表

顺序
参数类型
示例
说明
1
位置参数
a, b
必填,按顺序传递
2
默认参数
c=10
可选,有默认值
3
可变位置参数
*args
接收多余位置参数
4
命名关键字参数
*, d
必须用关键字传递
5
可变关键字参数
**kwargs
接收多余关键字参数

完整参数顺序示例

defcomplete_example(a, b, c=10, *args, d=20, **kwargs):print(f"位置参数: a={a}, b={b}")print(f"默认参数: c={c}")print(f"可变位置参数: args={args}")print(f"命名关键字参数: d={d}")print(f"可变关键字参数: kwargs={kwargs}")complete_example(12345, d=30, e=40, f=50)# 输出:# 位置参数: a=1, b=2# 默认参数: c=3# 可变位置参数: args=(4, 5)# 命名关键字参数: d=30# 可变关键字参数: kwargs={'e': 40, 'f': 50}

🎯 返回值与作用域

返回值详解

基本返回值

defadd(a, b):"""两数相加"""return a + bresult = add(35)print(result)  # 输出:8

返回多个值

实际上返回的是元组。

defget_coordinates():"""获取坐标"""    x = 10    y = 20return x, y  # 等价于 return (x, y)# 接收返回值coords = get_coordinates()print(coords)  # 输出:(10, 20)print(type(coords))  # 输出:<class 'tuple'># 解包赋值x, y = get_coordinates()print(f"x={x}, y={y}")  # 输出:x=10, y=20

返回函数(闭包)

defmultiplier(factor):"""创建乘法函数"""defmultiply(x):return x * factorreturn multiply# 创建不同的乘法函数times_two = multiplier(2)times_three = multiplier(3)print(times_two(5))  # 输出:10print(times_three(5))  # 输出:15

无返回值

defprint_message(message):"""打印消息,无返回值"""print(message)# 隐式返回 Noneresult = print_message("Hello")print(result)  # 输出:None

变量作用域

局部变量与全局变量

# 全局变量global_var = "我是全局变量"defdemo_scope():# 局部变量    local_var = "我是局部变量"print(f"函数内访问全局变量: {global_var}")print(f"函数内访问局部变量: {local_var}")demo_scope()print(f"函数外访问全局变量: {global_var}")# print(local_var)  # 报错:局部变量在函数外不可访问# 输出:# 函数内访问全局变量: 我是全局变量# 函数内访问局部变量: 我是局部变量# 函数外访问全局变量: 我是全局变量

使用global关键字修改全局变量

count = 0# 全局变量defincrement():"""增加计数"""global count  # 声明使用全局变量    count += 1print(f"函数内count: {count}")increment()increment()print(f"函数外count: {count}")# 输出:# 函数内count: 1# 函数内count: 2# 函数外count: 2

函数嵌套与作用域链

defouter():    outer_var = "外层函数变量"definner():        inner_var = "内层函数变量"print(f"内层访问外层: {outer_var}")print(f"内层访问内层: {inner_var}")    inner()# print(inner_var)  # 报错:内层变量在外层不可访问outer()# 输出:# 内层访问外层: 外层函数变量# 内层访问内层: 内层函数变量

作用域规则总结

规则
说明
示例
LEGB原则
查找顺序:Local → Enclosing → Global → Built-in
函数内变量优先查找局部作用域
局部变量
函数内定义,函数外不可访问
def f(): x = 1
全局变量
函数外定义,整个程序可访问
x = 1; def f(): print(x)
global关键字
在函数内修改全局变量
global x; x = 2
nonlocal关键字
在嵌套函数中修改外层变量
nonlocal x; x = 2

🎨 高级特性

Lambda表达式(匿名函数)

Lambda表达式用于创建简单的匿名函数。

基本语法

# lambda语法lambda arguments: expression# 等价的普通函数deffunction_name(arguments):return expression

Lambda示例

# 示例1:无参数say_hello = lambda"Hello, World!"print(say_hello())  # 输出:Hello, World!# 示例2:单个参数square = lambda x: x ** 2print(square(5))  # 输出:25# 示例3:多个参数add = lambda x, y: x + yprint(add(35))  # 输出:8# 示例4:带条件表达式max_num = lambda a, b: a if a > b else bprint(max_num(1020))  # 输出:20

Lambda与内置函数结合

# map函数:对每个元素应用函数numbers = [12345]squared = list(map(lambda x: x ** 2, numbers))print(squared)  # 输出:[1, 4, 9, 16, 25]# filter函数:筛选符合条件的元素numbers = [12345678910]evens = list(filter(lambda x: x % 2 == 0, numbers))print(evens)  # 输出:[2, 4, 6, 8, 10]# sorted函数:自定义排序students = [    {'name''Alice''age'20},    {'name''Bob''age'18},    {'name''Charlie''age'22}]sorted_students = sorted(students, key=lambda x: x['age'])print(sorted_students)# 输出:[{'name': 'Bob', 'age': 18}, {'name': 'Alice', 'age': 20}, {'name': 'Charlie', 'age': 22}]

Lambda工厂函数

defmake_multiplier(factor):"""创建乘法函数"""returnlambda x: x * factortimes_two = make_multiplier(2)times_three = make_multiplier(3)print(times_two(10))  # 输出:20print(times_three(10))  # 输出:30

装饰器(Decorator)

装饰器用于在不修改原函数的情况下,给函数添加新功能。

基础装饰器

defmy_decorator(func):"""简单装饰器"""defwrapper():print("函数执行前...")        func()print("函数执行后...")return wrapper@my_decoratordefsay_hello():print("Hello, Python!")say_hello()# 输出:# 函数执行前...# Hello, Python!# 函数执行后...

带参数的装饰器

defrepeat(times):"""重复执行函数"""defdecorator(func):defwrapper(*args, **kwargs):for _ inrange(times):                result = func(*args, **kwargs)return resultreturn wrapperreturn decorator@repeat(times=3)defgreet(name):print(f"Hello, {name}!")greet("码趣师")# 输出:# Hello, 码趣师!# Hello, 码趣师!# Hello, 码趣师!

实用装饰器示例

import timefrom functools import wraps# 计时装饰器deftimer(func):"""计算函数执行时间"""    @wraps(func)defwrapper(*args, **kwargs):        start_time = time.time()        result = func(*args, **kwargs)        end_time = time.time()print(f"{func.__name__} 执行时间: {end_time - start_time:.4f}秒")return resultreturn wrapper# 缓存装饰器defcache(func):"""缓存函数结果"""    memo = {}    @wraps(func)defwrapper(*args):if args in memo:print(f"从缓存获取: {args}")return memo[args]        result = func(*args)        memo[args] = resultreturn resultreturn wrapper@timer@cachedeffibonacci(n):"""计算斐波那契数列"""if n <= 1:return nreturn fibonacci(n-1) + fibonacci(n-2)print(fibonacci(10))# 输出:# fibonacci 执行时间: 0.0001秒# 55

高阶函数

高阶函数是指接收函数作为参数或返回函数的函数。

map函数

# 对列表中每个元素求平方numbers = [12345]squared = list(map(lambda x: x ** 2, numbers))print(squared)  # 输出:[1, 4, 9, 16, 25]# 将字符串列表转换为整数列表str_numbers = ['1''2''3''4''5']int_numbers = list(map(int, str_numbers))print(int_numbers)  # 输出:[1, 2, 3, 4, 5]

filter函数

# 筛选偶数numbers = [12345678910]evens = list(filter(lambda x: x % 2 == 0, numbers))print(evens)  # 输出:[2, 4, 6, 8, 10]# 筛选非空字符串strings = ['hello''''world''''python']non_empty = list(filter(lambda s: s, strings))print(non_empty)  # 输出:['hello', 'world', 'python']

reduce函数

from functools import reduce# 计算列表乘积numbers = [12345]product = reduce(lambda x, y: x * y, numbers)print(product)  # 输出:120# 字符串拼接words = ['Hello'' ''World''!']sentence = reduce(lambda x, y: x + y, words)print(sentence)  # 输出:Hello World!

🎮 实战案例

案例1:计算器程序

defcalculator():"""简单计算器"""defadd(a, b):return a + bdefsubtract(a, b):return a - bdefmultiply(a, b):return a * bdefdivide(a, b):if b == 0:raise ValueError("除数不能为零")return a / b    operations = {'+': add,'-': subtract,'*': multiply,'/': divide    }print("🧮 简单计算器")print("支持的操作:+ - * /")try:        num1 = float(input("请输入第一个数字: "))        op = input("请输入操作符: ")        num2 = float(input("请输入第二个数字: "))if op notin operations:print("❌ 不支持的操作符")return        result = operations[op](num1, num2)print(f"✅ 结果: {num1}{op}{num2} = {result}")except ValueError as e:print(f"❌ 错误: {e}")except Exception as e:print(f"❌ 发生错误: {e}")# 调用计算器# calculator()

案例2:数据分析工具

defanalyze_data(data):"""数据分析工具"""defcalculate_mean(numbers):"""计算平均值"""returnsum(numbers) / len(numbers) if numbers else0defcalculate_median(numbers):"""计算中位数"""        sorted_nums = sorted(numbers)        n = len(sorted_nums)if n == 0:return0elif n % 2 == 1:return sorted_nums[n // 2]else:return (sorted_nums[n // 2 - 1] + sorted_nums[n // 2]) / 2defcalculate_std(numbers):"""计算标准差"""        mean = calculate_mean(numbers)        variance = sum((x - mean) ** 2for x in numbers) / len(numbers)return variance ** 0.5deffind_outliers(numbers, threshold=2):"""找出异常值"""        mean = calculate_mean(numbers)        std = calculate_std(numbers)        outliers = [x for x in numbers ifabs(x - mean) > threshold * std]return outliers    results = {'count'len(data),'sum'sum(data),'mean': calculate_mean(data),'median': calculate_median(data),'std': calculate_std(data),'min'min(data) if data else0,'max'max(data) if data else0,'outliers': find_outliers(data)    }return results# 使用示例data = [10121213121114131510100]results = analyze_data(data)print("📊 数据分析结果")for key, value in results.items():print(f"{key}{value}")# 输出:# 📊 数据分析结果# count: 11# sum: 222# mean: 20.181818181818183# median: 12.0# std: 26.835915937906613# min: 10# max: 100# outliers: [100]

案例3:用户管理系统

classUserSystem:"""用户管理系统"""def__init__(self):self.users = []self.next_id = 1defadd_user(self, name, age, email, **kwargs):"""添加用户"""        user = {'id'self.next_id,'name': name,'age': age,'email': email,            **kwargs        }self.users.append(user)self.next_id += 1return userdefget_user(self, user_id):"""根据ID获取用户"""for user inself.users:if user['id'] == user_id:return userreturnNonedefupdate_user(self, user_id, **kwargs):"""更新用户信息"""        user = self.get_user(user_id)if user:            user.update(kwargs)return userreturnNonedefdelete_user(self, user_id):"""删除用户"""        user = self.get_user(user_id)if user:self.users.remove(user)returnTruereturnFalsedeflist_users(self, **filters):"""列出用户,支持筛选"""        result = self.usersfor key, value in filters.items():            result = [u for u in result if u.get(key) == value]return resultdefget_user_stats(self):"""获取用户统计信息"""ifnotself.users:return {}        ages = [u['age'for u inself.users]return {'total_users'len(self.users),'avg_age'sum(ages) / len(ages),'min_age'min(ages),'max_age'max(ages)        }# 使用示例system = UserSystem()# 添加用户user1 = system.add_user("码趣师"25"code@example.com", city="北京")user2 = system.add_user("学习者"22"learn@example.com", city="上海")user3 = system.add_user("开发者"30"dev@example.com", city="深圳")print("✅ 用户添加成功")print(f"用户1: {user1}")print(f"用户2: {user2}")print(f"用户3: {user3}")# 更新用户updated = system.update_user(1, age=26, city="杭州")print(f"\n✅ 用户更新: {updated}")# 查询用户user = system.get_user(1)print(f"\n🔍 查询用户: {user}")# 列出用户beijing_users = system.list_users(city="北京")print(f"\n📍 北京用户: {beijing_users}")# 统计信息stats = system.get_user_stats()print(f"\n📊 用户统计: {stats}")# 删除用户deleted = system.delete_user(3)print(f"\n🗑️ 删除用户: {deleted}")

案例4:文本处理工具

deftext_processor():"""文本处理工具"""defcount_words(text):"""统计单词数"""        words = text.split()returnlen(words)defcount_chars(text, include_spaces=False):"""统计字符数"""if include_spaces:returnlen(text)else:returnlen(text.replace(' '''))deffind_longest_word(text):"""找出最长单词"""        words = text.split()ifnot words:returnNonereturnmax(words, key=len)defreverse_text(text):"""反转文本"""return text[::-1]defremove_duplicates(text):"""去除重复单词"""        words = text.split()        seen = set()        result = []for word in words:if word notin seen:                seen.add(word)                result.append(word)return' '.join(result)defcapitalize_words(text):"""首字母大写"""return' '.join(word.capitalize() for word in text.split())return {'count_words': count_words,'count_chars': count_chars,'find_longest_word': find_longest_word,'reverse_text': reverse_text,'remove_duplicates': remove_duplicates,'capitalize_words': capitalize_words    }# 使用示例processor = text_processor()text = "hello world hello python programming is fun"print("📝 文本处理示例")print(f"原文: {text}\n")print(f"单词数: {processor['count_words'](text)}")print(f"字符数(不含空格): {processor['count_chars'](text)}")print(f"字符数(含空格): {processor['count_chars'](text, include_spaces=True)}")print(f"最长单词: {processor['find_longest_word'](text)}")print(f"反转文本: {processor['reverse_text'](text)}")print(f"去重: {processor['remove_duplicates'](text)}")print(f"首字母大写: {processor['capitalize_words'](text)}")# 输出:# 📝 文本处理示例# 原文: hello world hello python programming is fun# 单词数: 7# 字符数(不含空格): 34# 字符数(含空格): 40# 最长单词: programming# 反转文本: nuf si gnimmargorp nohtyp olleh dlrow olleh# 去重: hello world python programming is fun# 首字母大写: Hello World Hello Python Programming Is Fun

⚠️ 初学者常见陷阱

陷阱1:可变对象作为默认参数

这是Python中最经典的陷阱之一。

# ❌ 错误示例defadd_item(item, items=[]):"""添加物品到列表"""    items.append(item)return itemsprint(add_item('apple'))  # 输出:['apple']print(add_item('banana'))  # 输出:['apple', 'banana'](不是预期的['banana']!)print(add_item('orange'))  # 输出:['apple', 'banana', 'orange']# ✅ 正确做法defadd_item(item, items=None):"""添加物品到列表"""if items isNone:        items = []    items.append(item)return itemsprint(add_item('apple'))  # 输出:['apple']print(add_item('banana'))  # 输出:['banana']print(add_item('orange'))  # 输出:['orange']

陷阱2:参数定义顺序错误

# ❌ 错误示例:默认参数在位置参数之前# def greet(name="World", greeting):  # 报错#     return f"{greeting}, {name}!"# ✅ 正确做法:位置参数在前,默认参数在后defgreet(greeting, name="World"):returnf"{greeting}{name}!"print(greet("Hello"))  # 输出:Hello, World!print(greet("Hi""Alice"))  # 输出:Hi, Alice!

陷阱3:忘记return语句

# ❌ 错误示例:忘记returndefcalculate_square(x):"""计算平方"""    result = x ** 2result = calculate_square(5)print(result)  # 输出:None(不是预期的25!)# ✅ 正确做法defcalculate_square(x):"""计算平方"""    result = x ** 2return resultresult = calculate_square(5)print(result)  # 输出:25

陷阱4:修改全局变量时忘记global

# ❌ 错误示例:忘记global关键字count = 0defincrement():    count += 1# 报错:UnboundLocalError# ✅ 正确做法count = 0defincrement():global count    count += 1increment()print(count)  # 输出:1

陷阱5:lambda表达式过于复杂

# ❌ 错误示例:lambda过于复杂,可读性差complex_func = lambda x, y: x ** 2 + y ** 2if x > y else (x + y) if x < y else x * y# ✅ 正确做法:使用普通函数defcomplex_func(x, y):"""复杂计算"""if x > y:return x ** 2 + y ** 2elif x < y:return x + yelse:return x * y

陷阱总结表

陷阱
问题
解决方案
可变默认参数
默认参数在函数调用间共享
使用None作为默认值
参数顺序错误
默认参数在位置参数前
位置参数在前,默认参数在后
忘记return
函数返回None而不是预期值
确保使用return语句
忘记global
无法修改全局变量
使用global关键字声明
lambda过于复杂
可读性差
改用普通函数定义

🎯 总结与进阶

核心知识点回顾

主题
关键点
函数定义
使用def关键字,注意缩进和冒号
参数类型
位置、关键字、默认、可变、命名关键字
返回值
单值、多值(元组)、函数、None
作用域
LEGB原则,local、enclosing、global、builtin
lambda
匿名函数,适合简单表达式
装饰器
函数增强,AOP编程
高阶函数
map、filter、reduce

进阶学习路径

  1. 1. 函数式编程:深入学习functools模块
  2. 2. 生成器函数:yield关键字和生成器表达式
  3. 3. 异步函数:async/await语法
  4. 4. 类型注解:使用typing模块增强代码可读性
  5. 5. 函数性能优化:使用@lru_cache等装饰器

编码建议

# ✅ 最佳实践示例from typing importListDictOptionalCallablefrom functools import lru_cachedefprocess_data(    data: List[Dict[strany]],    key: str,    callback: Optional[Callable] = None) -> List[any]:"""    处理数据的函数    Args:        data: 数据列表        key: 要提取的键        callback: 可选的回调函数    Returns:        处理后的数据列表    """    result = [item.get(key) for item in data if key in item]if callback:        result = [callback(item) for item in result]return result@lru_cache(maxsize=128)defexpensive_computation(n: int) -> int:"""昂贵的计算,使用缓存优化"""if n <= 1:return nreturn expensive_computation(n-1) + expensive_computation(n-2)# 使用示例data = [    {'name''Alice''age'25},    {'name''Bob''age'30},    {'name''Charlie''age'35}]ages = process_data(data, 'age'lambda x: x * 2)print(ages)  # 输出:[50, 60, 70]

🎉 恭喜你完成Python函数基础教程的学习!

函数是Python编程的核心概念,掌握好函数的使用,你的代码将更加模块化、可维护和高效。记住:多练习、多思考、多实践,才能真正掌握函数的精髓!

我是你的Python学习搭子,专注用最白话的方式讲技术。关注我,下次更新时系统会第一时间提醒你。我们下期见!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-02-10 23:07:27 HTTP/2.0 GET : https://f.mffb.com.cn/a/474859.html
  2. 运行时间 : 0.118476s [ 吞吐率:8.44req/s ] 内存消耗:4,576.98kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=260ba67f11375e12ddf10e8f36f1bd22
  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.000402s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000598s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.013872s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000275s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000595s ]
  6. SELECT * FROM `set` [ RunTime:0.000213s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000590s ]
  8. SELECT * FROM `article` WHERE `id` = 474859 LIMIT 1 [ RunTime:0.000908s ]
  9. UPDATE `article` SET `lasttime` = 1770736047 WHERE `id` = 474859 [ RunTime:0.009090s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.007037s ]
  11. SELECT * FROM `article` WHERE `id` < 474859 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.001073s ]
  12. SELECT * FROM `article` WHERE `id` > 474859 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.001944s ]
  13. SELECT * FROM `article` WHERE `id` < 474859 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.004323s ]
  14. SELECT * FROM `article` WHERE `id` < 474859 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003228s ]
  15. SELECT * FROM `article` WHERE `id` < 474859 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.003446s ]
0.120042s