Python String zfill() နည်းလမ်း
ဥပမာ
စာလုံး 10 လုံးရှည်သည်အထိ သုညဖြင့် စာကြောင်းကိုဖြည့်ပါ။
txt = "50"
x = txt.zfill(10)
print(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
zfill()
နည်းလမ်းသည် သတ်မှတ်ထားသော အရှည်သို့ရောက်သည်အထိ string ၏အစတွင် သုည (0) ကို ပေါင်းထည့်သည် ။
len parameter ၏တန်ဖိုးသည် string ၏အရှည်ထက်နည်းပါက၊ ဖြည့်စွက်ခြင်းမပြုပါ။
အထားအသို
string.zfill(len)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
len | Required. A number specifying the desired length of the string |
နောက်ထပ် ဥပမာများ
ဥပမာ
စာလုံး 10 လုံးရှည်သည်အထိ ကြိုးများကို သုညဖြင့်ဖြည့်ပါ။
a = "hello"
b = "welcome to the jungle"
c = "10.000"
print(a.zfill(10))
print(b.zfill(10))
print(c.zfill(10))