အက္ခရာ(alphabet letter)များ a မှ z အထိ ဖြစ်သည်။ နံပါတ်(numbers)များသည် 0 မှ 9 အထိ ဖြစ်သည်။ အက္ခရာ(alphabet letter)များ နှင့် နံပါတ်(numbers)များကို ပေါင်း၍ alphanumeric ဟုခေါ်သည်။ alphanumeric တွင် အက္ခရာ(alphabet letter)များဖြစ်သည့် a မှ z အထိနှင့် နံပါတ်(numbers)များဖြစ်သည့် 0 မှ 9 တို့ပါဝင်သည်။ (space) နှင့် ! # % & ? စသည့် character များသည် alphanumeric တွင် မပါဝင်ပါ။)
အက္ခရာ(alphabet letter)များ၊ နံပါတ်(numbers)များ နှင့် (space) နှင့် ! # % & ? စသည့်တို့ကို character များဟုခေါ်သည်။
dir() function¶Python3 တွင် dir() သည် powerful inbuilt function တစ်ခုဖြစ်သည်။ object ၏ attributes များနှင့် method များကို ထုတ်ပေးသည်။ Functions , modules, strings, lists, dictionaries စသည်တို့သည့် object များ ဖြစ်ကြသည်။
dir() function သည် သတ်မှတ်ထားသည့် object များ၏ method များနှင့် properties ကို ပြန်ပေးသည်။ မည်သည့်တန်ဖိုးကို မှ ထုတ်ပေးလိမ့်မည်မဟုတ်ပေ။(dir() function returns all properties and methods of the specified object, without the values)
my_string= "I love Python."
print(dir(my_string))
.capitlize() method¶ပထမဆုံး character သည် အက္ခရာ(alphabet letter)ဖြစ်လျှင် ထိုအက္ခရာကို အကြီးစာလုံးသို့ ပြောင်းပေးသည်။(returns a string where the first character is upper case.)
my_string1 = "first letter of the sentence will be capitalized."
print(my_string1.capitalize()) # capitalizes the first letter of the string.
my_string1_a = "36 is my age."
print (my_string1_a.capitalize())
.casefold() method¶အက္ခရာများအားလုံးကို အသေးစာလုံးသို့ပြောင်းပေးသည်။ (returns a string where all the characters are lower case.) ။.lower()method နှင့်တူညီသော်လည်း.lower() method ထက်ပို အစွမ်းထက်သည်။(casefold() method is stronger, more aggressive)
my_string2 = "THIS SENTENCE WILL BECOME LOWER-CASED"
print(my_string2.casefold())
my_string2_a = "THIS SENTENCE WILL BECOME LOWER-CASED"
print(my_string2_a.lower())
.center() method¶Character အရေအတွက်ထည့်ပေးရသည်။ ထို character အရေအတွက်၏ အလယ်တွင် string ကို ဖော်ပြပေးမည်။ (will center align the string, using a specified character (space is default) as the fill character.) အလယ်တွင် string ကို နေရာချထားလိုသည့်အခါတွင် အသုံးပြုသည်။
my_string3 = " I love Python."
print(my_string3.center(60))
print("----original string below----")
print(my_string3)
my_string3 = "banana"
print(my_string3)
x = my_string3.center(20, "O")
print(x)
#Character အရေအတွက်ကို ဘယ်လောက်ထည့်ပေးရမယ်ဆိုတာ မစဥ◌စားဘဲ
#အရှေ့ (၂)လုံး၊အရှေ့ (၂)လုံး ပေါင်း (၄)လုံးထည့်မယ်ဆိုပြီးလည်း ရေးလို့ရပါတယ်။
print(my_string3.center(len(my_string3)+4, "@"))
.count() method¶စာကြောင်း သို့မဟုတ် စာလုံး(word)အတွင်း၌ မိမိသတ်မှတ်ပေးလိုက်သည့် အက္ခရာ၏ အရေအတွက်ကို ဖော်ပြပေးသည်။ (returns the number of elements with the specified value.)။ String အတွက်သာမက number, list, tuple စသည့်အမျိုးအစားများအတွင်းရှိ မိမိသတ်မှတ်ပေးလိုက်သည့် အက္ခရာ၏ အရေအတွက်ကိုလည်း ဖော်ပြပေးနိုင်သည်။
my_string4 = "fdfposGJsufH23edHHHHye23edffosidgs23edHHae66623ed6hw23edgw"
print(my_string4.count("H")) # returns the count of string "23" in the original string.
မိမိသတ်မှတ်ပေးသည့် starting index နေရာမှ စ၍ ending index အဆုံးနေရာအတွင်း၌သာ ရေတွက်ခြင်း(counting) ပြုလုပ်နိုင်သည်။ ("string being serached", starting index (optional), ending index(optional))
my_string4 = "fdfposGJsufH23edHHHHye23edffosidgs23eduiae66623ed6hw23edgw"
print(my_string4.count("H", 0, 20))
.encode() method¶ထည့်ပေးသည့် string ကို သတ်မှတ်လိုက်သည့် encoding မျိုးဖြင့် encode လုပ်ပေးသည်။ ဘာမှ မသတ်မှတ်ပေးလျှင် UTF-8 ဖြင့် encode လုပ်ပေးသည်။(encodes the string, using the specified encoding. If no encoding is specified, UTF-8 will be used.)
my_string5 = "My name is Ståle"
x=my_string5.encode(encoding="utf-8", errors="strict")
print(x)
print("----original string below----")
print(my_string5)
print(my_string5.encode(encoding="ascii",errors="backslashreplace"))
.endswith() method¶အဆုံး အက္ခရာများကို စစ်ပေးသည်။ သတ်မှတ်ထားသည့် character နှင့် အဆုံးသတ်သည် ဆိုလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပေးသည်။ (returns True if the string ends with the specified value, otherwise False.)
string.endswith(value, start, end)အစနှင့် အဆုံးထည့်ပေးလျှင် ထိုအစနှင့် အဆုံးအတွင်း၌သာ ရှာသည်။
my_string6 = "I love Python."
print(my_string6.endswith("hon."))
# Returns True if the original string ends in the string passed as argument. Otherwise returns False
print("----original string below----")
print(my_string6)
.expandtabs() method¶ပုံမှန်အားဖြင့် \t သည် tab တစ်ခုစာ ခြားပေးသည်။ Tab တစ်ခုသည် space (၄)နေရာ(4 spaces)နှင့် ညီသည်။
.expandtabs() method ကိုသုံး၍ မိမိအလိုရှိသည့် space အရေအတွက် အတိုင်းခြားပေးသည်။ ဥပမာ .expandtabs(10) သည် space (၁၀) နေရာ(10 spaces) ခြားပေးသည်။ string.expandtabs(tabsize)
my_string7 = "I love \tPython."
print(my_string7.expandtabs(0)) # it expands the tab character from original 4 spaces to the number passed as argument.
print("----original string below----")
print(my_string7)
txt = "H\te\tl\tl\to"
x = txt.expandtabs(0)# character တစ်လုံးနှင့် တစ်လုံးအကြားတွင် space နေရာ လုံးဝမထားရန်
x3 = txt.expandtabs(3)# character တစ်လုံးနှင့် တစ်လုံးအကြားတွင် space (၃)နေရာ ခြားပေးရန်
print(x)
print(x3)
.find() method¶.find() method သည် ရှာခိုင်းသည့် အက္ခရာ ၊ စာလုံး၏ ပထမဆုံး တွေ့ရှိသည့်တည်ရှိရာနေရာကို ဖော်ပြပေးသည်။ (finds the first occurrence of the specified value.)။ ထိုအက္ခရာ ၊ ထိုစာလုံး မရှိပါက -1 ထုတ်ပေးသည်။ (returns -1 if the value is not found.)
my_string8 = "I love Python."
print(my_string8.find("Py"))
print(my_string8.find("My"))
# tells starting index of the string that is passed as argument inside .find() method.
.format() method¶.format() method ကို သုံး၍ string ကို မိမိအလိုရှိသလို ပုံစံချ(format) နိုင်သည်။(returns the formatted string.)
တွန့်ကွင်း(curly brackets: {}) သည် placeholder ဖြစ်သည်။ string ၏ placeholder အတွင်း၌ မိမိအလိုရှိသည့် specified value(s) ကို ထည့်နိုင်သည်။ output များကို ဖော်ပြရာတွင် အလွန်အသုံးဝင်သည်။
my_string9 = " I love {} Python {}. "
print(my_string9.format("placeholder1", "placeholder2"))
# places the arguments positionally in the placeholders inside string.
print("----original string below----")
print(my_string9)
my_string9_a = "For only {price:.2f} dollars!" # Example
print(my_string9_a.format(price = 49))
myorder = "I have a {carname}, it is a {model}." # Example
print(myorder.format(carname = "Ford", model = "Mustang"))
#Example
quantity = 3
itemno = 567
price = 49
myorder = "I want {} pieces of item number {} for {:.2f} dollars."
print(myorder.format(quantity, itemno, price))
Index number များ ကို အသုံးပြု၍လည်း လုပ်နိုင်သည်။ ထို index number ကို curly brackets { } အတွင်း ထည့်ပေးရမည်။ (can use index numbers (a number inside the curly brackets {0}) to be sure the values are placed in the correct placeholders)။
အောက်တွင် ဥပမာ ဖြင့် ဖော်ပြထားသည်။
#Example (refer to the same value more than once, use the index number:)
age = 36
name = "John"
txt = "His name is {1}. {1} is {0} years old."
print(txt.format(age, name))
.format_map() method¶.format_map() method ကို dictionary များ၏ key နှင့် value ဖော်ပြရာတွင် အသုံးပြုသည်။ (used to return an dictionary key's value.)။ Dictionary တွင် အတွဲလိုက်ရှိသည့် key နှင့် value ကို အတူတကွ ဖော်ပြရန်အတွက် သုံးသည်။
my_dict = { "name" : "Kaung",
"birth city": "Yangon" }
# dictionary that will be passed as argument to .format_map() method.
my_string10 = " {name}'s place of birth is {birth city} "
print(my_string10.format_map(my_dict))
# Takes a single argument which is input dictionary. Places the values in place of keys mentioned.
.index() method¶ပထမဆုံးတွေ့သည့် နေရာကို ဖော်ပြပေးသည်။(returns the position at the first occurrence of the specified value.)။
"I love Python." တွင် o (၂)လုံးပါရှိရာ မည့်သည့်နေရာအတွင်းရှာပေးပါဟု မပြောလျှင် အစမှ အဆုံးအတွင် ရှာပေးပြီး ပထမဆုံးတွေ့သည့်နေရာကို ဖော်ပြပေးသည်။ ဒုတိယ o အတွက် အစ နှင့် အဆုံးနေရာ သတ်မှတ်ပေးသည်။
my_string11 = "I love Python."
print(my_string11.index("o")) # first occurrence
print(my_string11.index("o", 5, 12))
.isalnum()method¶Character များအားလုံးသည် alphanumeric ဖြစ်နေလျှင် True ပြန်ပေးသည်။ Alphanumeric တွင် အက္ခရာ(alphabet letter)များဖြစ်သည့် a မှ z အထိနှင့် နံပါတ်(numbers)များဖြစ်သည့် 0 မှ 9 အတွင်း တို့ပါဝင်သည်။ (space) နှင့် ! # % & ? စသည့် character များသည် alphanumeric တွင် မပါဝင်ပါ။)
my_string12 = "LovePython3"
print(my_string12)
print(my_string12.isalnum())
# checks whether all the characters in a given string are alphanumeric or not. Returns boolean
my_string12_a = "I love Python"
print(my_string12_a)
print(my_string12_a.isalnum())
# alphanumeric means only alphabet or numbers. So this returns false as it includes spaces.
.isalpha() method¶Character များအားလုံးသည် a မှ z အထိ အက္ခရာ(alphabet letter)ထဲမှ ဖြစ်နေလျှင် True ပြန်ပေးသည်။
(returns True if all the characters are alphabet letters (a-z))။
အက္ခရာ(alphabet letter) မဟုတ်သည့် character များမှာ 0 မှ 9 အထိ နံပါတ်(numbers)များနှင့် (space) နှင့် ! # % & ? စသည့်တို့ ဖြစ်သည်။
my_string13 = "Kaung" #alphabet
print(my_string13)
print(my_string13.isalpha())
# checks whether the string consists of alphabetic characters only or not.
my_string13_a = "I love Python" # not alphabet because of "space"
print(my_string13_a)
print(my_string13_a.isalpha())
.isascii() method¶ASCII characters ဆိုသည်မှာ print ထုတ်၍ ရသည့် characters ( that have a printable representation)ဖြစ်သည်။ U+0000 မှ U+007F အတွင်း ဖြစ်သည်။
For example, ° is changed to \xb0.
my_string14 = "I love Python."
print(my_string14)
print(my_string14.isascii()) # checks whether all characters in the string are ASCII or not.
my_string14_a = "ÆðþŊ" # non-ASCII characters
print(my_string14_a)
print(my_string14_a.isascii())
print(ascii('°'))
print(type(ascii('°')))
.isdecimal() method¶Character များ အားလုံးသည် ဒဿမကိန်းများ ဖြစ်နေလျှင် True ပြန်ပေးသည်။ (returns True if all the characters are decimals (0-9).)။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။
my_string15 = "64329"
print(my_string15)
print(my_string15.isdecimal())
my_string15_a = "64f3 29"
print(my_string15_a)
print(my_string15_a.isdecimal())
my_string15_b = "\u0033" #unicode for 3
print(my_string15_b.isdecimal())
my_string15_c = "\u0030" #unicode for 0
print(my_string15_c.isdecimal())
my_string15_d = "\u0047" #unicode for G
print(my_string15_d.isdecimal())
.isdigit() method¶Character များ အားလုံးသည် digit များ ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။ (returns True if all the characters are digits, otherwise False.)
my_string16 = "6574292"
print(my_string16)
print(my_string16.isdigit())
my_string16_a = " 837hghhh4834 "
print(my_string16_a)
print(my_string16_a.isdigit())
# this returns false becuase it includes spaces and alphabet.
my_string16_b = "\u0030" #unicode for 0
print(my_string16_b.isdigit())
my_string16_c = "\u00B2" #unicode for ²
print(my_string16_c.isdigit())
.isidentifier() method¶String သည် valid identifier တစ်ခု ဖြစ်လျှင် True ပြန်ပေးသည်။ ထို့သို့ မဖြစ်ခဲ့ လျှင် False ပြန်ပေးသည်။
(returns True if the string is a valid identifier, otherwise False.)
String တစ်ခုသည် သည် alphanumeric letters (a-z) and (0-9),ဖြစ်နေလျှင်သော်လည်းကောင်း၊ underscores (_) ပါဝင်နေလျှင်သော်လည်းကောင်းvalid identifier ဖြစ်သည်။ valid identifier တစ်ခု ဖြစ်ရန် number ဖြင့်မစရ သို့မဟုတ် spaces မပါဝင်။
my_string17 = "I love Python."
print(my_string17.isidentifier())
a = "MyFolder"
print(a.isidentifier())
b = "Demo002"
print(b.isidentifier())
c = "2bring"
print(c.isidentifier())
d = "my demo"
print(d.isidentifier())
.islower() method¶Character များ အားလုံးသည် အသေးစာလုံး(lower case)များ ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။ (returns True if all the characters are in lower case, otherwise False.) နံပါတ်များ(Numbers) ၊ သင်္ကေတများ(symbols )နှင့် space များကို မစစ်ဆေးပါ။ alphabet များကို သာစစ်ဆေးပါသည်။
my_string18 = "I love Python."
print(my_string18.islower())
a = "Hello world!"
print(a.islower())
b = "hello 123"
print(b.islower())
c = "mynameisPeter"
print(c.islower())
.isnumeric() method¶Character များ အားလုံးသည် နံပါတ်များ(numeric (0-9)) ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။(returns True if all the characters are numeric (0-9), otherwise False.)
ထပ်ကိန်းများ နှင့် အပိုင်းကိန်းများကိုလည်း နံပါတ်များ(numeric) အဖြစ် သတ်မှတ်သည်။(Exponents, like ² and ¾ are also considered to be numeric values.)
my_string19 = "I love Python."
print(my_string19.isnumeric()) # checks whether the string is numeric or not.
a = "\u0030" #unicode for 0
print(a.isnumeric())
b = "\u00B2" #unicode for ²
print(b.isnumeric())
c = "10km2"
print(c.isnumeric())
.isprintable() method¶Character များ အားလုံးသည် ပုံနှိပ်ဖော်ပြနိုင်သည့် စာလုံးများ ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။ (returns True if all the characters are printable, otherwise False.)
ပုံနှိပ်ဖော်ပြနိုင်သည့် စာလုံးများ ဟုတ် မဟုတ် စစ်ဆေးရန် သုံးသည်။
my_string20 = "I love Python."
print(my_string20.isprintable())# checks whether the string can be printed or not.
my_string20_a = "Hello!\nAre you #1?"
x = my_string20_a .isprintable()
print(x)
.isspace() method¶String တစ်ခုအတွင်းရှိ character များ အားလုံးသည် whitespaces ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။(returns True if all the characters in a string are whitespaces, otherwise False.)
my_string21 = "I love Python."
print(my_string21.isspace()) # checks whether the string includes only spaces or not.
my_string2_a = " "
print(my_string2_a.isspace())
my_string2_b = " K "
print(my_string2_b.isspace())
.istitle() method¶စာလုံးများအားလုံးသည် အကြီးစာလုံး(upper case letter)ဖြင့် စပြီး ကျန်စာလုံးများသည် အသေးစာလုံး(lower case letters) ဖြစ်လျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။ (returns True if all words in a text start with a upper case letter, AND the rest of the word are lower case letters, otherwise False.)
သင်္ကေတများ(symbols) နှင့် နံပါတ်များ(numbers)နှင့်မသက်ဆိုင်ပါ။(Symbols and numbers are ignored.)
my_string22 = " I love Python. "
print(my_string22)
print(my_string22.istitle()) # checks whether the string is a title or not. For a string to be a title, its every word should start with a capital letter.
my_string22_a = " I love Python. "
print(my_string22_a.istitle())
a = "HELLO, AND WELCOME TO MY WORLD"
print(a.istitle())
b = "Hello"
print(b.istitle())
c = "22 Names"
print(c.istitle())
d = "This Is %'!?"
print(d.istitle())
.isupper() method¶Character များ အားလုံးသည် အကြီးစာလုံး(upper case)ဖြစ်နေလျှင် True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။ (returns True if all the characters are in upper case, otherwise False.)
သင်္ကေတများ(Symbols) နှင့် နံပါတ်များ(numbers)နှင့် မသက်ဆိုင်ပါ။ အက္ခရာများ(alphabet characters)ကိုသာ စစ်ဆေးသည်။ (Numbers, symbols and spaces are not checked, only alphabet characters.)
my_string23 = "KAUNG HTAT NYUNT"
print(my_string23.isupper()) # checks whether the string is all upper-case or not.
my_string23_a = "Kaung Htat Nyunt"
print(my_string23_a.isupper())
a = "@WORLD"
print(a.isupper())
b = "HELLO 123"
print(b.isupper())
String မှ character တစ်လုံးချင်းစီ( iterable items)ကို ယူ၍ သတ်မှတ်ထားသည့် character နှင့် ပေါင်းပေးသည်။(takes all items in an iterable and joins them into one string.)
my_string24 = " IlovePython"
print("--".join(my_string24))
print("----original string below----")
print(my_string24)
my_string24 = " IlovePython"
print(" ".join(my_string24)) # it takes any iterable as an argument. In this case I am passing string.
# it is joined using -- here in my example.
print("----original string below----")
print(my_string24)
.ljust() method¶String ကို ဘယ်ညှိပေးသည်။ (will left align the string, using a specified character (space is default) as the fill character.)။ သတ်မှတ်ထားသည့် character အရေအတွက် ထည့်ပေးရသည်။
my_string25 = "I love Python."
print(my_string25.ljust(70,'*')) # Here the space mentioned is 70.
print("----original string below----")
print(my_string25)
txt = "banana"
x = txt.ljust(20, "_")
print(x)
.lower() method¶String တစ်ခုမှ character များကို အသေးစာလုံး()အဖြစ်သိုပြောင်းပေးသည်။ (converts all uppercase characters to lowercase.) String တွင် အကြီးစာလုံး(uppercase character)များ မပါရှိပါက မူလ string အတိုင်းသာ ဖြစ်လိမ့်မည်။
my_string26 = " I love Python. "
print(my_string26.lower()) # converts each character in the string to lower-case.
print("----original string below----")
print(my_string26)
.lstrip() method¶Character ၏ အရှေ့တွင် ရှိသည့် မလိုလားအပ်သည့် space, comma စသည်တို့ကို ဖယ်ရှားပေးသည်။(removes any leading characters (space is the default leading character to remove))
my_string27 = " I love Python. "
print(my_string27.lstrip()) # it strips all the spaces present at the left side of the string.
print("----original string below----")
print(my_string27)
txt = ",,,,,ssaaww.....banana"
x = txt.lstrip(",.asw")
print(x)
.maketrans() method + translate() method¶.maketrans() method သည် translate() function တွင် သုံးရန်အတွက် translate table ကို ထုတ်ပေးသည်။ (This method returns a translate table to be used translate() function.)။ Translation လုပ်ပြီး dictionary ထဲတွင် key, value pair အဖြစ်သိမ်းဆည်းထားသည်။
my_string28 = "I love Python."
translation = my_string28.maketrans("IFHn", "1234")
# it creates a translation and store them as key, value pair in dictionary.
print(translation)
# translation is stored as Unicode representation of each character.
print(chr(73))
print(my_string28.translate(translation))
# translate() method applies the translation.
# It means it replaces each character with its corresponding translation that we generated earlier
print("----original string below----")
print(my_string28)
.partition() method¶.partition() method သည် သတ်မှတ်ပေးသည့်(specified) string ကို ရှာဖွေပြီး string ကို tuple (၃)ခု ဖြစ်အောင်ခွဲသည်။
သတ်မှတ်ပေးသည့်(specified string)ကို နောက်ဆုံးတွေ့သည့်နေရာကို မူတည်၍ tuple (၃)ခု ဖြစ်အောင်ခွဲသည်။ သတ်မှတ်ပေးသည့်(specified string) မတိုင်ခင်နေရာ(everything before the "match") သတ်မှတ်ပေးသည့်(specified string) ပါသည့်နေရာ( element contains the specified string.) သတ်မှတ်ပေးသည့်(specified string) ပါသည့်နေရာ နောက်ပိုင်း(everything after the "match") string.partition(value)
my_string29 = " I love Python."
print(my_string29.partition("love")) # it breaks the string in three parts. The argument passed is the separator. It is not to be confused with split. It always returns tuple having 3 items, keeping the string passed as argument as the middle item.
print("----original string below----")
print(my_string29)
my_string29_a = "I love apple."
print(my_string29_a.partition("love"))
# it breaks the string in three parts.
#The argument passed is the separator.
#It is not to be confused with split.
#It always returns tuple having 3 items, keeping the string passed as argument as the middle item.
.replace() method¶စာလုံး(phrase)တစ်ခုကို တခြားစာလုံး(phrase) ဖြင့် အစားထိုးသည်။ (replaces a specified phrase with another specified phrase.) အရှေ့စာလုံးသည် အစားထိုးခံရမည့်စာလုံး(phrase)ဖြစ်သည်။ အနောက်စာလုံးသည် အစားထိုးမည့် စာလုံး(phrase)ဖြစ်သည်။
my_string30 = " I love Python. "
print(my_string30.replace("Python", "apple"))
# it raplaces the string passed as first arguments with the string passed as second argument.
print("----original string below----")
print(my_string30)
.rfind()method¶နောက်ဆုံးတွေ့ခဲ့သည့်နေရာကို ဖော်ပြပေးသည်။(finds the last occurrence of the specified value.)။ အတူညီဆုံးဖြစ်သည့်နေရာကို ရှာပေးသည်။ (returns the starting index of the right most substring that matches)
တူသည့်စာကို ရှာမတွေ့ပါက -1 ထုတ်ပေးသည်။ (returns -1 if the value is not found.)
rfind() method သည် rindex() method ခပ်ဆင်ဆင်နှင့်တူညီသည်။
my_string31 = "I love Python."
print(my_string31.rfind("Py"))
my_string31 = "I love Python and Python."
print(my_string31.rfind("Py"))
.rindex() method¶နောက်ဆုံးတွေ့ခဲ့သည့်နေရာကို ဖော်ပြပေးသည်။(finds the last occurrence of the specified value.)။ အတူညီဆုံးဖြစ်သည့်နေရာကို ရှာပေးသည်။ (returns the starting index of the right most substring that matches) တူသည့်စာကို ရှာမတွေ့ပါက -1 ထုတ်ပေးသည်။ (returns -1 if the value is not found.) rindex() method သည် rfind() method ခပ်ဆင်ဆင်နှင့်တူညီသည်။
my_string32 = " I love Python."
print(my_string32.rindex("Py")) # it returns the index of the rightmost substring that matches the string passed as argument.
print("----original string below----")
print(my_string32)
txt = "Hello, welcome to my world."
x = txt.rindex("o")
print(x)
.rjust() method¶စာလုံးရေ ထည့်ပေးရသည်။ ထိုစာလုံးရေ နေရာတွင် ညာညှိ(right justified)ပေးသည်။(will right align the string, using a specified character (space is default) as the fill character.)
my_string33 = " I love Python. "
print(my_string33.rjust(50, "*"))
# စာလုံးရေ (၅၀)စာနေရာ(50 characters long)တွင် ညာညှိ(right justified)ပေးသည်။
print("----original string below----")
print(my_string33)
.rpartition() method¶.rpartition() method သည် သတ်မှတ်ပေးသည့်(specified) string ကို ရှာဖွေပြီး string ကို tuple (၃)ခု ဖြစ်အောင်ခွဲသည်။
သတ်မှတ်ပေးသည့်(specified string)ကို နောက်ဆုံးတွေ့သည့်နေရာကို မူတည်၍ tuple ၃ခု ဖြစ်အောင်ခွဲသည်။
သတ်မှတ်ပေးသည့်(specified string) မတိုင်ခင်နေရာ(everything before the "match")
သတ်မှတ်ပေးသည့်(specified string) ပါသည့်နေရာ( element contains the specified string.)
သတ်မှတ်ပေးသည့်(specified string) ပါသည့်နေရာ နောက်ပိုင်း(everything after the "match") string.rpartition(value)
my_string34 = "I am a student learning Computer Science. Computer Science is an amazing discipline. "
print(my_string34.rpartition("Computer"))
print("----original string below----")
print(my_string34)
.rsplit() method¶String တစ်ခုကို list တစ်ခု အဖြစ်ခွဲပေးသည်။ ညာဘက်စ၍ ခွဲပေးသည်။ (splits a string into a list, starting from the right.) "max" ကို မသတ်မှတ်ပေးလျှင် split() method မှ ထုတ်ပေးသည့် ရလဒ်နှင့် တူညီလိမ့်မည်။
Note: When maxsplit is specified, the list will contain the specified number of elements plus one.
my_string35 = "I love Python."
print(my_string35.rsplit(" "))
my_string35_a= "apple, banana, cherry"
print(my_string35_a.rsplit(",", 2))
.rstrip() method¶String တစ်ခုရှိ အဆုံး (trailing) character များကို ဖယ်ရှားပေးသည်။ string ၏ နောက်ဆုံး၌ ရှိသည့် space သည် ဖယ်ရှားပေ ရမည့်အရာဖြစ်သည်။ (removes any trailing characters (characters at the end a string), space is the default trailing character to remove.)
my_string36 = " I love Python....."
print(my_string36.rstrip("."))
# it strips off all the spaces present at the right side of the string.
my_string36_a = "banana,,,,,ssaaww....."
print(my_string36_a.rstrip(",.asw"))
.split() method¶String တစ်ခုကို list တစ်ခု အဖြစ်ခွဲပေးသည်။ (splits a string into a list.)
separator ကို သတ်မှတ်ပေးနိုင်သည်။ (can specify the separator, default separator is any whitespace.)
string.split(separator, maxsplit)
my_string37 = "I love Python."
print(my_string37.split())
print(my_string37.split(" ")) # same result
.splitlines() method¶String တစ်ခုကို list တစ်ခု အဖြစ်ခွဲပေးသည်။(splits a string into a list. ) စာကြောင်းအဆုံးတွင် line break ဖြစ်သည်။ (The splitting is done at line breaks.)
string.startswith(value, start, end)
my_string38 = " I love Python.\n I plan to learn Python because it is fun.\n These lines will be separated. "
print(my_string38)
print("--------------------------------------- ")
print(my_string38.splitlines())
print(my_string38.splitlines(True))
.startswith() method¶String တစ်ခုသည် သတ်မှတ်ထားသည့် character ဖြင့် စထားလျှင်
True ပြန်ပေးသည်။ ထိုသို့မဟုတ်လျှင် False ပြန်ပေးသည်။( returns true if the string begins with the characters, and false if not.) အကြီးစာလုံး အသေးစာလုံးမှန်ရန် လိုအပ်သည်။ case sensitive ဖြစ်သည်။)
string.startswith(value, start, end)
my_string39 = "I love Python. "
print(my_string39.startswith("i"))
print("----original string below----")
print(my_string39)
my_string39_a = "Hello, welcome to my world."
print(my_string39_a.startswith("wel", 7, 20))
.strip() method¶String ၏ အစနှင့် အဆုံးနေရာတို့တွင် ရှိနေသည့် space များကို ဖယ်ရှားပေးသည်။ (Remove spaces at the beginning and at the end of the string)
my_string40 = " I love Python. "
print(my_string40.strip()) #it strips off all the spaces present at the right side of the string.
print("----original string below----")
print(my_string40)
.swapcase() method¶String တစ်ခုရှိ အကြီးစာလုံးများ(upper case letters)ကို အသေးစားလုံး(lower case )များ အဖြစ်သို့လည်းကောင်း အသေးစားလုံး(lower case )များကို အကြီးစာလုံးများ (upper case letters)ဖြစ်သို့လည်းကောင် ပြောင်းပေးသည်။ (returns a string where all the upper case letters are lower case and vice versa.)
string.swapcase()
my_string41 = "I love Python."
print(my_string41.swapcase())
.title() method¶String တစ်ခုကို ခေါင်းစဥ(title) အဖြစ်ပြောင်းပေးသည်။ ခေါင်းစဥ(title)ဆိုသည်မှာ စာလုံး၏ အစ အက္ခရာသည် အကြီးစာလုံး ဖြစ်ရမည်။ စာလုံး(word)တိုင်း၏ ပထမ character ကို အကြီးစာလုံး(upper case)အဖြစ်ပြောင်းပေးသည်။ (returns a string where the first character in every word is upper case. Like a header, or a title.)
စာလုံး(word)တွင် သင်္ကေတများ( symbols )နှင့် နံပါတ်များ (numbers)ပါဝင်နေပါက ထို symbol သို့မဟုတ် နံပါတ်(number) နောက် character ကို ပြောင်းပေးသည်။ (If the word contains a number or a symbol, the first letter after that will be converted to upper case.)
my_string42 = " I love Python. "
print(my_string42.title()) # it makes first alphabet of each word capital.
my_string42_a = "Welcome to my 2nd world"
print(my_string42_a .title())
.upper() method¶String တစ်ခု အတွင်းရှိ character များအားလုံးကို အကြီးစာလုံး(upper case) ဖြစ်အောင် ပြောင်းပေးသည်။ (returns a string where all characters are in upper case.) သင်္ကေတများ( symbols )နှင့် နံပါတ်(numbers)များ မသက်ဆိုင်ပါ။ (Symbols and numbers are ignored.)
my_string44 = " I love Python. "
print(my_string44.upper()) # it makes all the characters capital.
my_string44_a = "this is string example....wow!!!"
print (my_string44_a.upper())
.zfill() method¶String ၏ အစတွင် zeros (0) ထည့်ပေးသည်။ မိမိသတ်မှတ်ထားသည့် အရှည်(specified length) ပြည့်အောင် ထည့်ပေးသည်။ (adds zeros (0) at the beginning of the string, until it reaches the specified length.)
.len() method ကို သုံး၍ မိမိအလိုရှိသည့် zeros (0) အရေအတွက်အတိုင်း ထည့်ပေါင်းပေးနိုင်သည်။ String ၏ အရှည်(length) မည်မျှ ရှိသည်ကို ရေတွက်နေရန် မလိုတော့ပေ။
string ၏ အရှည်သည် မိမိသတ်မှတ်ထားသည့် အရှည်(specified length)ထက်ပိုများနေပါက မထည့်ပေးပါ။ (If the value of the len parameter is less than the length of the string, no filling is done.)
string.zfill(len)
my_string45 = "I love Python."
print(my_string45.zfill(30))
print(my_string45.zfill(len(my_string45)+3))
print(my_string45.zfill(10))
a = "hello"
print(a.zfill(10))
b = "welcome to the jungle"
print(b.zfill(10))
c = "10.000"
print(c.zfill(10))
-End-