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

Python Getting the Maximum Value

Python Getting the Maximum Value

Document Object Reference Manual Python3 Examples

In the following example we use the max() method to find the maximum value:

Example (Python 3.0+)

-- coding: UTF-8 --

Filename : test.py

author by : www.runoob.com

The simplest

print

(

max

(

1

,

2

)

)

print

(

max

(

'

a

'

,

'

b

'

)

)

It can also be used on lists and tuples

print

(

max

(

[

1

,

2

]

)

)

print

(

max

(

(

1

,

2

)

)

)

More examples

print

(

"

The maximum of 80, 100, 1000 is:

"

,

max

(

80

,

100

,

1000

)

)

print

(

"

The maximum of -20, 100, 400 is:

"

,

max

(

20

,

100

,

400

)

)

print

(

"

The maximum of -80, -20, -10 is:

"

,

max

(

80

, -

20

, -

10

)

)

print

(

"

The maximum of 0, 100, -400 is:

"

,

max

(

0

,

100

, -

400

)

)

The output of the code above is:


2
b
2
2
80, 100, 1000 最大值为:  1000
-20, 100, 400最大值为:  400
-80, -20, -10最大值为:  -10
0, 100, -400最大值为: 100

Introduction to the max() function:Python max()function in Vue 3.

Document Object Reference Manual Python3 Examples