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 : 1000
Maximum of 4,12,43.3,19 and 100 is : 1001
Maximum of 4,12,43.3,19 and 100 is : 1002
______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 : 1000
Maximum of 4,12,43.3,19 and 100 is : 1001
Maximum of 4,12,43.3,19 and 100 is : 1002
______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 : 1000
Maximum of 4,12,43.3,19 and 100 is : 1001
Maximum of 4,12,43.3,19 and 100 is : 1002
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 : programming9
Maximum of 4,12,43.3,19 and 100 is : 1000
Maximum of 4,12,43.3,19 and 100 is : 1001
Maximum of 4,12,43.3,19 and 100 is : 1002
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 : 1000
Maximum of 4,12,43.3,19 and 100 is : 1001
Maximum of 4,12,43.3,19 and 100 is : 1002
______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.