print('lmy name is lizhenlei'.capitalize()) #首字母大寫
print('Lmy Name is LIZHENLEI123#'.casefold()) #全變成小寫
print('Lmy Name is LIZHENLEI123#'.center(50, '-')) #一共有50個字符,把字符串放到中間
print('Lmy Name is LIZHENLEI123#'.count('L')) #查詢一共有多少個L
print('你好'.encode('utf-8')) #轉換編碼方式
print('Lmy Name is LIZHENLEI123#'.endswith('#')) #判斷結尾是否是指定字符
print('Lmy Name is \tLIZHENLEI123#'.expandtabs(50)) #設定字符串中一個Tab的長度
print('me{} is{} 3#{}'.format('aaaa', 'bbbb', 'cccc')) #格式化字符串
print('Lmy Name is LIZHENLEI123#'.find('m')) #從左向右找到想要查找的內容,而且返回查找的第一個字母的下標
people = {'name':'lizhenlei', 'age':23}
print('My name is {name}, I {age}'.format_map(people)) #格式化字符串輸出
print('Lmy Name is LIZHENLEI123#'.isdigit())
print('123'.isdigit()) #是否爲數字
print('123abcBAC'.isalnum()) #是否爲字母和數字
print('123abcBAC'.isalpha()) #不知道啥意思
print('123abcBAC'.isdecimal()) #不知啥意思
print('123abcBAC'.isidentifier()) #判斷字符串是否是一個合法的變量名
print('123abc'.islower()) #判斷字符串中字母是否是都是小寫
print('123abc'.isnumeric()) #不知道啥意思
print('dobi123\n'.isprintable()) #判斷字符串是否爲可打印的,或者字符串爲空
print(' '.isspace()) #判斷字符串是否爲空格
print('My Name Is Lizhenlei'.istitle()) #判斷字符串中的字符是不是首字母大寫,其會忽視非字母字符。
print('ABC'.isupper()) #判斷字符串中是否都爲大寫字母
print('ABC'.index('A')) #與 find() rfind() 相似,不一樣的是若是找不到,就會引起 ValueError。
print('-'.join(['2012', '3', '12'])) #用指定的字符串,鏈接元素爲字符串的可迭代對象。
print('ABC'.ljust(10,'a')) #返回指定長度的字符串,字符串內容居左(右)若是長度小於字符串
# 長度,則返回原始字符串,默認填充爲 ASCII 空格,可指定填充的字符串。
print('ABC123#'.lower()) #將字符串中的大寫字母變成小寫字母
print('\n ABC123# \n'.lstrip()) #去掉左邊的空格和回車
a = 'dobi is a dog'
table = str.maketrans('dobi', 'alph')
print(a.translate(table)) #maktrans 是一個靜態方法,用於生成一個對照表,以供 translate 使用。
#若是 maktrans 僅一個參數,則該參數必須是一個字典,字典的 key 要麼是一個 Unicode 編碼(一個整數),
# 要麼是一個長度爲 1 的字符串,字典的 value 則能夠是任意字符串、None或者 Unicode 編碼。
print('ABC123#'.partition('A')) #按字符串的內容切割字符串
print('dog wow wow jiao'.replace('wow', 'wang')) #按規則替換字符串的內容
print('ABC123#A'.rfind("A")) #從右向左找字母
print('ABC123#A'.rindex('A')) #從右向左找字母 若是找不到,就會引起 ValueError。
print('ABC123#A'.rjust(50, 'a')) #在字符串左邊補空格
print('ABC123#A'.rpartition('A')) #按規則切割字符串
print('ABC123#A'.rsplit()) #不太清楚
print('ABC123#A'.rstrip()) #不太清楚
print('ABC123#A'.split())
print('ABC123#A'.splitlines())
print('ABC123#A'.startswith())
print('ABC123#A'.strip())
print('ABC123#A'.swapcase())
print('ABC123#A'.translate())
print('ABC123#'.title()) #將字符串中每一個「單詞」首字母大寫。其判斷「單詞」的依據則是
# 基於空格和標點,因此應對英文撇好全部格或一些英文大寫的簡寫時,會出錯。
print('abc123#'.upper()) #將字符串中的小寫字母變成大寫字母
print('abc123#'.zfill(10)) #用 '0' 填充字符串,並返回指定寬度的字符串。