#!/usr/bin/env python# -*- coding: utf-8 -*-# Author:Caesar yangname = 'yuE yu \tqing is {my} net {name}'# print(name.capitalize())#首字母轉為大寫print(name. ...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:Caesar yang
name = 'yuE yu \tqing is {my} net {name}'
#------------------------------------------------------------------
print(name.capitalize())#首字母轉為大寫
print(name.count('y'))#統計'y'有幾個
print(name.casefold())#將所有大寫變成小寫(支持多種國家語言)
print(name.center(60,'-'))#列印60位字元,不夠位數用'-'填充,name居中
print('我最帥'.encode('utf-8'))#轉為二進位
print(name.endswith('g'))#判斷變數是否以'g'結尾
print(name.expandtabs(tabsize=10))#將Tab轉為10位空格
print(name.find('qing'))#用來檢測字元串中是否包含子字元串
print(name.format(my = 'caesar',name = 'yue yu qing'))#按照格式轉換
print(name.format_map({'my':'caesar','name':'yue yu qing'}))#字典格式轉換
#----------------------------------------------------------------------------------------
print(name.isalnum())#判斷是否是阿拉伯字母與數字
print(name.isalpha())#判斷是否是純英文字母
print(name.isdecimal())#判斷是否是十進位數
print(name.isdigit())#判斷是否是整數
print(name.isidentifier())#判斷是否是合法的標識符(變數名)
print(name.islower())#判斷是否全是小寫
print(name.isnumeric())#判斷是否只有數字
print(name.isspace())#判斷是否是空格
print(name.istitle())#判斷每個字元串首字母都是大寫
print(name.isprintable())#判斷是否能列印 #tty file,drive file不可列印
print(name.isupper())#判斷是否全是大寫
#----------------------------------------------------------------------------------------
print('*'.join(['a','b','c']))#將‘*‘插入到'a','b','c'中,結果:a*b*c
print(name.ljust(50,'*'))#長度50,不夠的右邊填充'*'
print(name.rjust(50,'*'))#長度50,不夠的左邊填充'*'
print(name.lower())#大寫變小寫(只支持英文)
print(name.upper())#小寫變大寫(只支持英文)
print('\naaaaa\n'.strip())#去掉回車
print('\naaaaa\n'.lstrip())#去掉左邊回車
print('\naaaaa\n'.rstrip())#去掉右邊回車
#--------------------------------------------------------
intab = "abcd"
outtab = "1234"
str_trantab = str.maketrans(intab,outtab)
test_str = "csdn blog: http://blog.csdn.net/wirelessqa"
print (test_str.translate(str_trantab))
#轉換
#----------------------------------------------------------
print(name.replace('y','Y',2))#替換
print(name.rfind('i'))#從左找'i'
print(name.split())#將字元串以空格為間隔生成列表*可以自定義字元作為間隔
print('my name is \nCaesar'.splitlines())#將字元串以換行符\n為間隔生成列表
print(name.swapcase())#大小寫互換
print(name.title())#將首字母轉為大寫
print(name.zfill(30))#不夠30用0左邊填充