"함수 index()"의 두 판 사이의 차이

5번째 줄: 5번째 줄:
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<source lang='Python'>
fruits = ['Banana', 'Orange', 'Apple', 'Orange', 'Mango']
fruits = ['Banana', 'Orange', 'Apple', 'Orange', 'Mango', 'Orange']
print( fruits.index('Orange') )
print( fruits.index('Orange') )
# 1
# 1
print( fruits.index('Orange', 2) )
print( fruits.index('Orange', 4) )
# 5
print( fruits.index('Orange', 2, 6) )
# 3
# 3
</source>
</source>

2014년 8월 20일 (수) 13:53 판

index

Python

fruits = ['Banana', 'Orange', 'Apple', 'Orange', 'Mango', 'Orange']
print( fruits.index('Orange') )
# 1
print( fruits.index('Orange', 4) )
# 5
print( fruits.index('Orange', 2, 6) )
# 3
fruits = ['Banana', 'Orange', 'Apple', 'Mango']
print( fruits.index('Pineapple') )
# ValueError: 'Pineapple' is not in list
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}