Hướng dẫn how do you find the minimum and maximum value in python? - làm thế nào để bạn tìm thấy giá trị nhỏ nhất và lớn nhất 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.
 


Làm thế nào để bạn tìm thấy mức tối thiểu trong Python?

Hàm python min () trả về giá trị thấp nhất trong danh sách các mục.Min () có thể được sử dụng để tìm số nhỏ nhất trong danh sách hoặc chuỗi đầu tiên sẽ xuất hiện trong danh sách nếu danh sách được đặt hàng theo thứ tự bảng chữ cái.min() function returns the lowest value in a list of items. min() can be used to find the smallest number in a list or first string that would appear in the list if the list were ordered alphabetically.

Làm thế nào để bạn tìm thấy giá trị tối đa 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.The max() function 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 giá trị tối thiểu và tối đa?

Ứng dụng thực tế. If f"(x) > 0 for some value of x, say x = b, then the function f(x) is minimum at x = b.