# Python3 演示代碼
# 翻譯使用
# maketrans() 和 translate()
# uk 設置為字符翻譯
str1 = " wy "
#指定替換為 str2 = "gf"
# 刪除字符
str3 = "u"
# 目標t string
trg = "weeksyourweeks"
# 使用maketrans() for
# 編譯翻譯
# table table le = trg.maketrans (str1, str2, str3)
#打印原行
print ( "翻譯前的字符串是:" 代碼> , end = "")
print (trg)
< br> # 使用 translate() 進行翻譯。
print ( "翻譯後的字符串是:“ , end = " ") 打印 (trg.translate(table)) 輸出: 翻譯前的字符串是:weeksyourweeks 翻譯後的字符串是:pythonengineering 翻譯不用layouttrans() 翻譯也可以通過指定翻譯字典並作為一個對像傳遞來實現,該對象充當顯示。在這種情況下,不需要 maketrans() 來執行翻譯。 代碼 #2: 沒有 layouttrans() 的翻譯代碼。
# Python3 演示代碼
# 無翻譯
# maketrans ( )
# 顯示規範
# 使用 ASCII
table = { 119 : 103 , 121 : 102 , 117 : None cod e> }
# 目標字符串
trg = "weeksyourweeks"
# 打印原始行
print ( "翻譯前的字符串是:" , end 代碼> = " ")
print (trg)
# 使用 translate ( ) 進行翻譯。
print ( "翻譯後的字符串是:" , end = "")
打印 (trg.translate(table))
輸出: 翻譯前的字符串是:weeksyourweeks 翻譯後的字符串是:pythonengineering 應用程序: 在許多情況下,在編碼或開發過程中可能會出現錯誤,這些函數提供了簡單快捷的方法來替換和修復它們,並可能為您節省大量時間。
Shop
Learn programming in R: courses $
Best Python online courses for 2022 $
Best laptop for Fortnite $
Best laptop for Excel $
Best laptop for Solidworks $
Best laptop for Roblox $
Best computer for crypto mining $
Best laptop for Sims 4 $
Latest questions
NUMPYNUMPY
psycopg2: insert multiple rows with one query
12 answers
NUMPYNUMPY
How to convert Nonetype to int or string?
12 answers
NUMPYNUMPY
How to specify multiple return types using type-hints
12 answers
NUMPYNUMPY
Javascript Error: IPython is not defined in JupyterLab
12 answers
Wiki
Python OpenCV | cv2.putText () method
numpy.arctan2 () in Python
Python | os.path.realpath () method
Python OpenCV | cv2.circle () method
Python OpenCV cv2.cvtColor () method
Python - Move item to the end of the list
time.perf_counter () function in Python
Check if one list is a subset of another in Python
Python os.path.join () method
|