Python 3 内置函数 - `max()`函数

本文详细介绍了Python3中的max()函数,包括其用法、示例和帮助文档。通过实例演示如何在不同场景下利用max()找到序列中的最大值,适合初学者理解该核心内置函数的运用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python 3 内置函数 - max()函数

0. max() 函数

返回最大值,参数可以为序列。

1. 使用方法

>>> help(max)
# output:
Help on built-in function max in module builtins:

max(...)
	## 使用方法
    max(iterable, *[, default=obj, key=func]) -> value
    max(arg1, arg2, *args, *[, key=func]) -> value
    
    With a single iterable argument, return its biggest item. The
    default keyword-only argument specifies an object to return if
    the provided iterable is empty.
    With two or more arguments, return the largest argument.

2. 使用示例

示例1.

>>> max(0,1,2,9)
# output:
9

示例2.

>>> list(range(5)), max(range(5))
# output:
([0, 1, 2, 3, 4], 4)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值