Python next() လုပ်ဆောင်ချက်
ဥပမာ
iterator တစ်ခုဖန်တီးပြီး အရာများကို တစ်ခုပြီးတစ်ခု ပရင့်ထုတ်ပါ-
mylist = iter(["apple", "banana", "cherry"])
x =
next(mylist)
print(x)
x = next(mylist)
print(x)
x = next(mylist)
print(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
လုပ်ဆောင်ချက်သည် နောက်တစ်ခု next()
အား ထပ်ကာထပ်ကာဖြင့် ပြန်ပေးသည်။
၎င်းသည် ၎င်း၏ အဆုံးသို့ ရောက်ရှိသွားပါက ပြန်လာရန် မူရင်းပြန်တန်ဖိုးကို သင်ထည့်နိုင်သည်။
အထားအသို
next(iterable, default)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
iterable | Required. An iterable object. |
default | Optional. An default value to return if the iterable has reached to its end. |
နောက်ထပ် ဥပမာများ
ဥပမာ
iterable သည် ၎င်း၏ အဆုံးသို့ ရောက်သောအခါ မူရင်းတန်ဖိုးကို ပြန်ပေးသည်-
mylist = iter(["apple", "banana", "cherry"])
x =
next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)
x =
next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)