菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 3 教程
Python3 教程 Python3 简介 Python3 环境搭建 Python3 VScode Python3 基础语法 Python3 基本数据类型 Python3 数据类型转换 Python3 解释器 Python3 注释 Python3 运算符 Python3 数字(Number) Python3 字符串 Python3 列表 Python3 元组 Python3 字典 Python3 集合 Python3 条件控制 Python3 循环语句 Python3 编程第一步 Python3 推导式 Python3 迭代器与生成器 Python3 with Python3 函数 Python3 lambda Python3 装饰器 Python3 数据结构 Python3 模块 Python __name__ Python3 输入和输出 Python3 File Python3 OS Python3 错误和异常 Python3 面向对象 Python3 命名空间/作用域 Python 虚拟环境的创建 Python 类型注解 Python3 标准库概览 Python3 实例 Python 测验

Python3 高级教程

Python3 正则表达式 Python3 CGI编程 Python3 MySQL(mysql-connector) Python3 MySQL(PyMySQL) Python3 网络编程 Python3 SMTP发送邮件 Python3 多线程 Python3 XML 解析 Python3 JSON Python3 日期和时间 Python3 内置函数 Python3 MongoDB Python3 urllib Python uWSGI 安装配置 Python3 pip Python3 operator Python math Python requests Python random Python OpenAI Python 有用的资源 Python AI 绘画 Python statistics Python hashlib Python 量化 Python pyecharts Python selenium 库 Python 爬虫 Python Scrapy 库 Python Markdown Python sys 模块 Python Pickle 模块 Python subprocess 模块 Python queue 模块 Python StringIO 模块 Python logging 模块 Python datetime 模块 Python re 模块 Python csv 模块 Python threading 模块 Python asyncio 模块 Python PyQt Python for 循环 Python while 循环
(追記) (追記ここまで)

Python 获取最大值函数

Document 对象参考手册 Python3 实例

以下实例中我们使用max()方法求最大值:

实例(Python 3.0+)

# -*- coding: UTF-8 -*-# Filename : test.py# author by : www.runoob.com# 最简单的print(max(1, 2))print(max('a', 'b'))# 也可以对列表和元组使用print(max([1,2]))print(max((1,2)))# 更多实例print("80, 100, 1000 最大值为: ", max(80, 100, 1000))print("-20, 100, 400最大值为: ", max(-20, 100, 400))print("-80, -20, -10最大值为: ", max(-80, -20, -10))print("0, 100, -400最大值为:", max(0, 100, -400))

执行以上代码输出结果为:

2
b
2
2
80, 100, 1000 最大值为: 1000
-20, 100, 400最大值为: 400
-80, -20, -10最大值为: -10
0, 100, -400最大值为: 100

max() 函数介绍:Python max()函数。

Document 对象参考手册 Python3 实例

AI 思考中...

5 篇笔记 写笔记

  1. #0

    小辉

    447***[email protected]

    21
    # 对比任意多个数字的大小

    参考:

    N = int(input('输入需要对比大小数字的个数:'))
    print("请输入需要对比的数字:")
    num = []
    for i in range(1,N+1):
     temp = int(input('输入第 %d 个数字' % i))
     num.append (temp)
    print('您输入的数字为:',num)
    print('最大值为:',max(num))

    小辉

    447***[email protected]

    9年前 (2017年12月23日)
  2. #0

    mahu

    wuc***[email protected]

    13

    参考方法:

    N = int(input('输入需要对比大小数字的个数:\n'))
    num=[ int(input('请输入第 %d 个对比数字 \n'%(i)))for i in range(1,N+1)]
    print('您输入的数字为:',list(num))
    print('最大值为: ',max(num))
    

    mahu

    wuc***[email protected]

    9年前 (2018年01月25日)
  3. #0

    卡夫卡的甲壳虫

    458***[email protected]

    11

    相比以上不用输入对比大小数字的个数:

    a = []
    while True:
     """输入q来结束输入数字"""
     try:
     a.append(int(input("输入数字: ")))
     break
     except ValueError:
     print("输入的不是数字")
    while a[-1] != 'q':
     c = input("输入数字: ")
     if c != 'q':
     try:
     a.append(int(c))
     except ValueError:
     print("输入的不是数字")
     else:
     a.append(c)
    del a[-1]
    print("最大数字是",max(a))

    卡夫卡的甲壳虫

    458***[email protected]

    7年前 (2019年04月20日)
  4. #0

    zeliangchu

    zel***[email protected]

    34

    感觉比楼上的稍微好理解一点:

    #-*- coding UTF-8 -*-
    #author by:Lebron
    a=[]
    while True:
     #输入q来结束输入数字
     c=input('请输入数字:')
     if c!='q':
     try:
     i=int(c)
     a.append(i)
     except ValueError:
     print('输入的不是数字')
     else:
     break
    print('最大数字是:',max(a))

    zeliangchu

    zel***[email protected]

    7年前 (2019年07月31日)
  5. #0

    王二狗

    wy1***[email protected]

    3

    max() 比较字符串的大小,依次比较字符串的 assic 码:

    ls = []
    num = input('输入要比较大小的字符串的个数')
    for i in range(num):
     temp = input('输入第%d个字符串'%(i+1))
     ls.append(temp)
     
    print(max(ls))

    王二狗

    wy1***[email protected]

    4年前 (2022年10月21日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /