Python List index() နည်းလမ်း
ဥပမာ
တန်ဖိုး "ချယ်ရီ" ၏အနေအထားကဘာလဲ။
fruits = ['apple', 'banana', 'cherry']
x = fruits.index("cherry")
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် index()
သတ်မှတ်ထားသောတန်ဖိုး၏ ပထမအကြိမ်တွင် အနေအထားကို ပြန်ပေးသည်။
အထားအသို
list.index(elmnt)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
elmnt | Required. Any type (string, number, list, etc.). The element to search for |
နောက်ထပ် ဥပမာများ
ဥပမာ
တန်ဖိုး 32 ၏ အနေအထားကား အဘယ်နည်း။
fruits = [4,
55, 64, 32, 16, 32]
x =
fruits.index(32)
မှတ်ချက်- နည်းလမ်း index()
သည် တန်ဖိုး၏ ပထမဆုံး ဖြစ်ပေါ်မှုကိုသာ ပြန်ပေးသည်။