錯誤類型:translate() takes exactly one argument (2 given) in python error
python3标準庫,str.translate(tabel)
- table -- 翻譯表,翻譯表是通過maketrans方法轉換而來。
- 記錄一下代碼:
def test():
#先創造一個a
a = '0123aaa44'
#maketrans生成table,右邊的值替換左邊的值,注意長度和内容必須一一對應
table = str.maketrans('0123456789','abcdefghij')
#生成新的str
b = a.translate(table)
#列印b
print(b)
test()
結果:abcdaaaee