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