Python String Light() Method
ဥပမာ
"ငှက်ပျောဖူး" ဟူသော စကားလုံး၏ ဘယ်ဘက်တွင် ရှည်လျားသော အက္ခရာ 20 လုံးအား ပြန်ပေးပါ။
txt = "banana"
x = txt.ljust(20)
print(x, "is my
favorite fruit.")
မှတ်ချက်- ရလဒ်တွင်၊ ငှက်ပျောသီး၏ညာဘက်တွင် အဖြူကွက် ၁၄ ခုရှိသည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် ljust()
ဖြည့်စွက်ဇာတ်ကောင်အဖြစ် သတ်မှတ်ထားသော အက္ခရာ (space သည် ပုံသေဖြစ်သည်) ကို အသုံးပြု၍ string ကို ဘယ်ဘက်သို့ ညှိပါမည်။
အထားအသို
string.ljust(length, character)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
length | Required. The length of the returned string |
character | Optional. A character to fill the missing space (to the right of the string). Default is " " (space). |
နောက်ထပ် ဥပမာများ
ဥပမာ
အက္ခရာ "O" ကို padding စာလုံးအဖြစ် အသုံးပြုခြင်း-
txt = "banana"
x = txt.ljust(20, "O")
print(x)