- list.pop():要素の取り出し
サンプルコード:sample_352.py
x = ["a", "b", "c"]
print(x.pop(0))
print(x)
実行結果
a
['b', 'c']
サンプルコード:sample_353.py
x = [1, 2, 3]
print(x.pop(1))
print(x)
実行結果
2
[1, 3]
サンプルコード:sample_354.py
x = [1, 2, 3]
print(x.pop())
print(x)
実行結果
3
[1, 2]
サンプルコード:sample_355.py
x = [1, 2, 3]
print(x.pop(3))
print(x)
実行結果
IndexError: pop index out of range
サンプルコード:sample_356.py
x = []
print(x.pop())
実行結果
IndexError: pop from empty list