LoginSignup
1
2

More than 3 years have passed since last update.

【Python】リストとタプルの最大値を取得

Posted at

最大値と最小値を求める組み込み関数の引数の与え方が複数あるようなので、検証してみた。
リストでも、タプルでも最大値、最小値は取得できる。

まず普通の与え方

max_num = max(1, 5, 10)
min_num = min(1, 5, 10)
print(max_num) # 10
print(min_num) # 1

リストを引数として与える

test_list = [1, 5, 10]
max_num = max(test_list)
min_num = min(test_list)

print(max_num) # 10
print(min_num) # 1

タプルを引数として与える

test_tuple = (1, 5, 10)
max_num = max(test_tuple)
min_num = min(test_tuple)

print(max_num) # 10
print(min_num) # 1
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2