Python

List, strings

values = [1, -1, -2, 0]
*# Find the max and min elements.*
print(**max**(values))
print(**min**(values))1
-2

values = ["cat", "bird", "apple"]
*# Use max on the list of strings.*
result = **max**(values)
print(*"MAX"*, values, result)
*# Use min.*
result = **min**(values)
print(*"MIN"*, values, result)MAX ['cat', 'bird', 'apple'] cat
MIN ['cat', 'bird', 'apple'] apple

value1 = *100*
value2 = *-5*
*# Call max with two arguments.*
*# ... The larger argument is returned.*
maximum = **max**(value1, value2)
print(*"MAX"*, maximum)
*# Call min with two arguments.*
minimum = **min**(value1, value2)
print(*"MIN"*, minimum)
*# If the arguments are equal, max and min return that value.*
print(*"MAX"*, **max**(0, 0))
print(*"MIN"*, **min**(0, 0))MAX 100
MIN -5
MAX 0
MIN 0

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

No updates found for this page.