๐Ÿ—‚๏ธ2024.07.08 TIL

Donghyunยท2024๋…„ 7์›” 8์ผ
0

TIL (Today I Learned)

๋ชฉ๋ก ๋ณด๊ธฐ
11/53
post-thumbnail

Python

enumerate(): ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์ž๋ฃŒํ˜•์„ ์ž…๋ ฅ๋ฐ›์•˜์„ ๋•Œ, ์ธ๋ฑ์Šค์™€ ๊ฐ’์„ ๋™์‹œ์— ์ ‘๊ทผํ•˜์—ฌ ๋ฆฌํ„ด!

  • ์˜ˆ์‹œ
    # ์˜ˆ์‹œ ๋ฆฌ์ŠคํŠธ
    fruits = ['apple', 'banana', 'cherry', 'date']
    
    # enumerate() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ๋ฑ์Šค์™€ ๊ฐ’์„ ๋™์‹œ์— ๋ฐ˜๋ณต
    for index, fruit in enumerate(fruits):
        print(f"Index {index}: {fruit}")
  • ๊ฒฐ๊ณผ
    Index 0: apple
    Index 1: banana
    Index 2: cherry
    Index 3: date

์ฐธ๊ณ : https://velog.io/@ehdtkd98/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๊ฐ€์žฅ-๊ฐ€๊นŒ์šด-๊ธ€์ž-ํŒŒ์ด์ฌ-h8cccj2b

profile
๋ฐ์ดํ„ฐ๋ถ„์„ ๊ณต๋ถ€ ์ผ๊ธฐ~!

0๊ฐœ์˜ ๋Œ“๊ธ€