目录

基础 Python 学习路线推荐 : Python 学习目录 >> Python 基础入门

一.Python max 函数简介

max 函数返回给定参数的最大值,参数可以为序列语法:

# 返回值:返回参数中的最大值;
max( x, y, z, .... )

二.Python max 函数使用

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿说编程
@Blog(个人博客地址): www.codersrc.com
@File:Python max 函数.py
@Time:2021/05/09 08:00
@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!

"""

# max 支持两个或者多个参数,并返回最大值
print(max(1,5))
print(max(5.5,6100,1,-10,20))

'''
输出结果:

5
6100
'''

注意:max 函数中的类型只能是 int 或者 float 类型,其他类型会报错,例如:

# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:猿说编程
@Blog(个人博客地址): www.codersrc.com
@File:Python max 函数.py
@Time:2021/05/09 08:00
@Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!

"""

print(max(1,'a'))

TypeError: '>' not supported between instances of 'str' and 'int'

三.猜你喜欢

  1. Python 条件推导式
  2. Python 列表推导式
  3. Python 字典推导式
  4. Python 不定长参数 *argc/**kargcs
  5. Python 匿名函数 lambda
  6. Python return 逻辑判断表达式
  7. Python is 和 == 区别
  8. Python 可变数据类型和不可变数据类型
  9. Python 浅拷贝和深拷贝
  10. Python 异常处理
  11. Python 线程创建和传参
  12. Python 线程互斥锁 Lock
  13. Python 线程时间 Event
  14. Python 线程条件变量 Condition
  15. Python 线程定时器 Timer
  16. Python 线程信号量 Semaphore
  17. Python 线程障碍对象 Barrier
  18. Python 线程队列 Queue – FIFO
  19. Python 线程队列 LifoQueue – LIFO
  20. Python 线程优先队列 PriorityQueue
  21. Python 线程池 ThreadPoolExecutor(一)
  22. Python 线程池 ThreadPoolExecutor(二)
  23. Python 进程 Process 模块
  24. Python 进程 Process 与线程 threading 区别
  25. Python 进程间通信 Queue / Pipe
  26. Python 进程池 multiprocessing.Pool
  27. Python GIL 锁

未经允许不得转载:猿说编程 » Python max 函数

本文由博客 - 猿说编程 猿说编程 发布!

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/shuopython/p/15054429.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!