"""
字串最常見的資料型別,同時也是支援操作很多的型別,常用方法包括切片,分割,替換,填充,邊緣刪除等等.
"""
def section():
str_num = "012345678"
print(str_num[3:8:2])
def reverseSection():
str_num = "012345678"
print(str_num[5:1:-2])
def rightPadding():
str_num = "123"
print(str_num.ljust(7, "y"))
def leftPadding():
str_num = "123"
print(str_num.rjust(8, '*'))
def bothSidePadding():
str_num = "123"
print(str_num.center(9, "&"))
def cutLeftElement():
str_word = ' dasddsa '
print(str_word.lstrip(' '))
def cutRightElement():
str_word = ' dasddsa '
print(str_word.lstrip())
def cutElement():
str_word = " ddd ddd "
print(str_word.strip())
def divisionStr():
str_word = "We,are,champion"
print(str_word.split(",", maxsplit=1))
def judgeStart():
str_word = "bcd"
print(str_word.startswith(("a", "b", "c")))
def judgeEnd():
str_word = "bcd"
print(str_word.endswith(("a", "b", "c")))
def getIndex():
str_word = "abbcd"
print(str_word.index("b"))
print(str_word.rindex("c"))
def replace():
str_num = "012345671"
print(str_num.replace("1", "s", 1))
def join():
l = ('a','b','c')
d = {
'a':'1',
'b':'2',
'c':'3'
}
print('-'.join(l))
print('-'.join(d))
print('-'.join(d.values()))
本作品採用《CC 協議》,轉載必須註明作者和本文連結