Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Find the Minimum Element in a List

Python Find the Minimum Element in a List

Document Object Reference Manual Python3 Examples

Define a list of numbers and find the minimum element in the list.

For example:


输入 : list1 = [10, 20, 4]
输出 : 4 

Example 1

list1

=

[

10

,

20

,

4

,

45

,

99

]

 

list1.

sort

(

)

 

print

(

"The minimum element is:"

,

*list1

[

:

1

]

)

The output of the above example is:


最小元素为: 4

Example 2: Using the min() method

list1

=

[

10

,

20

,

1

,

45

,

99

]

 

print

(

"The minimum element is:"

,

min

(

list1

)

)

The output of the above example is:


最小元素为: 1

Document Object Reference Manual Python3 Examples