日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Python min()

內(nèi)置函數(shù)min()有助于返回給定 iterable 中的最小元素。也可以在兩個(gè)或多個(gè)參數(shù)之間找到最小的元素。

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比旬陽(yáng)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式旬陽(yáng)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋旬陽(yáng)地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。

 # to find the smallest item in an iterable
**min(iterable, *iterables, key, default)** 
 # to find the smallest item between two or more objects
**min(arg1, arg2, *args, key)** 

最小()參數(shù):

帶有 iterable 的min()函數(shù)具有以下參數(shù)。

*分鐘(可重復(fù),可重復(fù),鍵,默認(rèn))**

參數(shù)描述必需/可選
可迭代的諸如列表、元組、集合、字典等可條目。需要
*可重復(fù)任意數(shù)量的可滴定物;可以不止一個(gè)可選擇的
傳遞數(shù)據(jù)項(xiàng)并進(jìn)行比較的一種關(guān)鍵功能可選擇的
系統(tǒng)默認(rèn)值如果給定的 iterable 為空,則為默認(rèn)值可選擇的

不帶iterable()iterable()函數(shù)有以下參數(shù)。

【t0 min(arg1、arg2、*args、鍵)】的縮寫

參數(shù)描述必需/可選
arg1一個(gè)對(duì)象;可以是數(shù)字、字符串等需要
arg2一個(gè)對(duì)象;可以是數(shù)字、字符串等需要
*參數(shù)任意數(shù)量的對(duì)象可選擇的
傳遞每個(gè)參數(shù)并進(jìn)行比較的一個(gè)關(guān)鍵函數(shù)可選擇的

最小()返回值

在傳遞空迭代器的情況下,它會(huì)引發(fā) ValueError 異常。為了避免這種情況,我們可以傳遞默認(rèn)參數(shù)。 如果我們傳遞多個(gè)迭代器,那么從給定的迭代器中返回最小的項(xiàng)。

| 投入 | 返回值 | | 整數(shù) | 最小整數(shù) | | 線 | 具有最小 Unicode 值的字符 |

Python 中min()方法的示例

示例 1:獲取列表中最小的項(xiàng)目

 number = [13, 2, 8, 25, 10, 46]
smallest_number = min(number);

print("The smallest number is:", smallest_number)
Output 

輸出:

The smallest number is: 2

示例 2:列表中最小的字符串

 languages = ["Python", "C Programming", "Java", "JavaScript"]
smallest_string = min(languages);

print("The smallest string is:", smallest_string) 

輸出:

The smallest string is: C Programming

示例 3:在字典中查找min()

 square = {2: 4, 3: 9, -1: 1, -2: 4}

# the smallest key
key1 = min(square)
print("The smallest key:", key1)    # -2

# the key whose value is the smallest
key2 = min(square, key = lambda k: square[k])

print("The key with the smallest value:", key2)    # -1

# getting the smallest value
print("The smallest value:", square[key2])    # 1 

輸出:

TThe smallest key: -2
The key with the smallest value: -1
The smallest value: 1

例 4:在給定的數(shù)字中找出最小值

 result = min(4, -5, 23, 5)
print("The minimum number is:", result) 

輸出:

The minimum number is -5

示例 5:查找對(duì)象的最小值()

 class Data:
    id = 0

    def __init__(self, i):
        self.id = i

    def __str__(self):
        return 'Data[%s]' % self.id

def get_data_id(data):
    return data.id

# min() with objects and key argument
list_objects = [Data(1), Data(2), Data(-10)]

print(min(list_objects, key=get_data_id)) 

輸出:

Data[-10]

網(wǎng)頁(yè)標(biāo)題:創(chuàng)新互聯(lián)Python教程:Python min()
文章位置:http://www.5511xx.com/article/djdiiop.html