Hướng dẫn how do you use max and min in python? - làm thế nào để bạn sử dụng max và min trong python?

Bài viết này mang đến cho bạn một chức năng rất thú vị và ít được biết đến của Python, cụ thể là Max () và Min (). Bây giờ khi so sánh với đối tác C ++ của họ, chỉ cho phép hai đối số, quá nghiêm ngặt là nổi, int hoặc char, các chức năng này không chỉ giới hạn ở 2 yếu tố, mà còn có thể giữ nhiều yếu tố như đối số và cũng hỗ trợ các chuỗi trong các đối số của chúng, từ đó Cho phép hiển thị chuỗi nhỏ nhất hoặc lớn nhất về mặt từ vựng. Chức năng chi tiết được giải thích dưới đây. & NBSP;not only limited to 2 elements, but can hold many elements as arguments and also support strings in their arguments, hence allowing to display lexicographically smallest or largest string as well. Detailed functionality are explained below.
 

Hàm này được sử dụng để tính toán tối đa các giá trị được truyền trong đối số của nó và giá trị lớn nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
 

Syntax : 
max(a,b,c,..,key,default)
Parameters : 
a,b,c,.. :  similar type of data.
key : key function where the iterables are passed and comparison is performed
default : default value is passed if the given iterable is empty
Return Value : 
Returns the maximum of all the arguments.
Exceptions : 
Returns TypeError when conflicting types are compared.

Python3

print("Maximum of 4,12,43.3,19 and 100 is : "

Maximum of 4,12,43.3,19 and 100 is : 100
0
Maximum of 4,12,43.3,19 and 100 is : 100
1
Maximum of 4,12,43.3,19 and 100 is : 100
2

______7

Đầu ra: & nbsp; & nbsp;
 

Maximum of 4,12,43.3,19 and 100 is : 100

Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
 

Syntax : 
min(a,b,c,.., key,default)
Parameters : 
a,b,c,.. :  similar type of data.
key : key function where the iterables are passed and comparison is performed
default : default value is passed if the given iterable is empty
Return Value : 
Returns the minimum of all the arguments.
Exceptions : 
Returns TypeError when conflicting types are compared.

Python3

print(

Syntax : 
min(a,b,c,.., key,default)
Parameters : 
a,b,c,.. :  similar type of data.
key : key function where the iterables are passed and comparison is performed
default : default value is passed if the given iterable is empty
Return Value : 
Returns the minimum of all the arguments.
Exceptions : 
Returns TypeError when conflicting types are compared.
9
Maximum of 4,12,43.3,19 and 100 is : 100
0
Maximum of 4,12,43.3,19 and 100 is : 100
1
Maximum of 4,12,43.3,19 and 100 is : 100
2

______7

Đầu ra: & nbsp; & nbsp;
 

Minimum of 4,12,43.3,19 and 100 is : 4

Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;

______7These functions throw TypeError when conflicting data types are compared.
 

Python3

print(

Minimum of 4,12,43.3,19 and GeeksforGeeks is : 
9
Maximum of 4,12,43.3,19 and 100 is : 100
0
Maximum of 4,12,43.3,19 and 100 is : 100
1
Maximum of 4,12,43.3,19 and 100 is : 100
2

Ngoại lệ

Đầu ra: & nbsp; & nbsp;
 

Minimum of 4,12,43.3,19 and GeeksforGeeks is : 

Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;
 

Traceback (most recent call last):
  File "/home/b5da1d7f834a267f94fbbefe1b31a83c.py", line 7, in 
    print (min( 4,12,43.3,19,"GeeksforGeeks" ) )
TypeError: unorderable types: str() < int()

______7

Ngoại lệlexicographically largest and smallest of Strings i.e String appearing first in dictionary or last.
 

Python3

print(

The word occurring 1st in dict. among given is : algorithm
The word occurring last in dict. among given is : programming
9
Maximum of 4,12,43.3,19 and 100 is : 100
0
Maximum of 4,12,43.3,19 and 100 is : 100
1
Maximum of 4,12,43.3,19 and 100 is : 100
2

1. Kiểu hàng hóa: Các chức năng này ném loại khi so sánh các loại dữ liệu xung đột. & NBSP;

print((7

Maximum of 4,12,43.3,19 and 100 is : 100
0
Maximum of 4,12,43.3,19 and 100 is : 100
1
Maximum of 4,12,43.3,19 and 100 is : 100
2

______7

Đầu ra: & nbsp; & nbsp;
 

The word occurring 1st in dict. among given is : algorithm
The word occurring last in dict. among given is : programming

Hàm này được sử dụng để tính toán tối thiểu các giá trị được truyền trong đối số của nó và giá trị nhỏ nhất về mặt từ vựng nếu các chuỗi được truyền dưới dạng đối số. & NBSP;Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 


Việc sử dụng Max () và Min () là gì?

Hàm SQL Min () và Max () Hàm Min () trả về giá trị nhỏ nhất của cột đã chọn.Hàm Max () trả về giá trị lớn nhất của cột đã chọn.The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column.

Làm thế nào để Max () hoạt động trong Python?

Hàm python max () hàm tối đa () hàm trả về mục có giá trị cao nhất hoặc mục có giá trị cao nhất trong một số không thể điều chỉnh được.Nếu các giá trị là chuỗi, một so sánh theo thứ tự bảng chữ cái được thực hiện.returns the item with the highest value, or the item with the highest value in an iterable. If the values are strings, an alphabetically comparison is done.

Làm thế nào để bạn tìm thấy chỉ số tối đa và tối thiểu trong Python?

Hàm Inbuilt của Python cho phép chúng tôi tìm thấy nó trong một dòng, chúng tôi có thể tìm thấy mức tối thiểu trong danh sách bằng hàm min () và sau đó sử dụng hàm index () để tìm ra chỉ mục của phần tử tối thiểu đó.find the minimum in the list using the min() function and then use the index() function to find out the index of that minimum element.

Làm thế nào để Min () hoạt động trong Python?

Hàm python min () hàm min () trả về mục có giá trị thấp nhất hoặc mục có giá trị thấp nhất trong một điều không thể sử dụng được.Nếu các giá trị là chuỗi, một so sánh theo thứ tự bảng chữ cái được thực hiện.returns the item with the lowest value, or the item with the lowest value in an iterable. If the values are strings, an alphabetically comparison is done.