Python String maketrans() နည်းလမ်း
ဥပမာ
မြေပုံဆွဲဇယားတစ်ခုကို ဖန်တီးပြီး translate()
မည်သည့် "S" စာလုံးကိုမဆို "P" စာလုံးဖြင့် အစားထိုးရန် နည်းလမ်းတွင် အသုံးပြုပါ-
txt = "Hello Sam!"
mytable = txt.maketrans("S", "P")
print(txt.translate(mytable))
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်းသည် သတ်မှတ်ထားသော စာလုံးများကို အစားထိုးရန်အတွက် နည်းလမ်းဖြင့် maketrans()
အသုံးပြုနိုင်သည့် မြေပုံဆွဲဇယားကို ပြန်ပေးသည် ။
translate()
အထားအသို
string.maketrans(x, y, z)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
x | Required. If only one parameter is specified, this has to be a dictionary describing how to perform the replace. If two or more parameters are specified, this parameter has to be a string specifying the characters you want to replace. |
y | Optional. A string with the same length as parameter x. Each character in the first parameter will be replaced with the corresponding character in this string. |
z | Optional. A string describing which characters to remove from the original string. |
နောက်ထပ် ဥပမာများ
ဥပမာ
စာလုံးများစွာကို အစားထိုးရန် မြေပုံဆွဲဇယားကို အသုံးပြုပါ-
txt = "Hi Sam!"
x = "mSa"
y = "eJo"
mytable = txt.maketrans(x,
y)
print(txt.translate(mytable))
ဥပမာ
မြေပုံဆွဲဇယားရှိ တတိယဘောင်သည် သင် string မှ ဖယ်ရှားလိုသော စာလုံးများကို ဖော်ပြသည်-
txt = "Good night Sam!"
x = "mSa"
y = "eJo"
z = "odnght"
mytable = txt.maketrans(x, y, z)
print(txt.translate(mytable))
ဥပမာ
maketrans()
နည်းလမ်းသည် အစားထိုးမှုတစ်ခုစီကို ဖော်ပြသည့် အဘိဓာန်တစ်ခုကို ယူနီကုဒ်တွင် ပြန်ပေးသည် -
txt = "Good night Sam!"
x = "mSa"
y = "eJo"
z = "odnght"
print(txt.maketrans(x, y, z))