Skip to content · ⁨コンテンツへスキップ⁩

Find the position

English

Find the position

Search a list and report where something is, counting from 0.

Loop over the positions with range(len(items)), so you have the index i as well as the item items[i]. return leaves the function straight away, which is exactly what you want at the first match. Return -1 only after the loop has checked every item.

日本語

位置を見つける

リストを検索し、0 から数えて某ものがどこにあるかを報告します。

range(len(items)) で位置をループして、インデックス i とアイテム items[i] の両方を取得します。 return は関数を直ちに終了させ、これは一致した最初の時点で必要な動作です。 -1 はすべてのアイテムを確認した後にのみ返します。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP