LoginSignup
0
0

More than 1 year has passed since last update.

リストから名前指定remove()したときに同じ名前の要素が複数あったらどうなるか

Last updated at Posted at 2021-09-12

気になったこと

python3のリスト操作で、remove()関数を使って指定した要素を削除することがありますが、リストの中に同じ要素があった場合にどのような消え方をするのかふと心配になったので確認しました。

確認結果

「apple」の文字列から「p」をremove()しましたが、消えた「p」は1個だけでした。安心しました。

>>> test_list = list("apple")
>>> print(test_list)
['a', 'p', 'p', 'l', 'e']

>>> test_list.remove("p")
>>> print(test_list)
['a', 'p', 'l', 'e']
0
0
2

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
0
0