【python】list②

pythonのlistの操作②。
リストに要素が存在しているか。

A = ['apple', 'orange', 'grape', 'banana']

'apple' in A
# Result: True # 

'carrot' in A
# Result: False # 

インデックスの検索。

A.index('grape')
# Result: 2 # 

リスト内に含まれる数。

A = ['apple', 'orange', 'grape', 'banana', 'apple']
A.count('apple')

# Result: 2 # 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA