Python 的 ascii(~)
方法以字符串形式返回對象的可打印表示形式。它使用 \x
、 \u
或 \U
轉義非 ASCII 字符。
參數
1. obj
| object
要為其返回可打印表示的對象。
返回值
輸入對象的可打印表示形式為字符串。
例子
基本用法
要返回 'marché'
的可打印表示形式:
ascii('marché')
"'march\\xe9'"
é
不是 ASCII 字符,因此它被轉義為 \xe9
。 \x
表示其後麵是一個十六進製值。
注意
輸出在double-quotes 內返回。這意味著當這個結果傳遞給eval()
時,我們將返回原始對象的正確轉義版本。在\xe9
之前添加額外的\
以使其轉義。
相關用法
- Python ascii()用法及代碼示例
- Python ast.MatchClass用法及代碼示例
- Python ast.ListComp用法及代碼示例
- Python ast.Lambda用法及代碼示例
- Python asyncio.BaseTransport.get_extra_info用法及代碼示例
- Python ast.IfExp用法及代碼示例
- Python unittest assertNotIsInstance()用法及代碼示例
- Python ast.Return用法及代碼示例
- Python Tkinter askopenfile()用法及代碼示例
- Python ast.Subscript用法及代碼示例
- Python asyncio.shield用法及代碼示例
- Python asyncio.run用法及代碼示例
- Python unittest assertIsNotNone()用法及代碼示例
- Python NumPy asscalar方法用法及代碼示例
- Python asyncio.wait_for用法及代碼示例
- Python asyncio.create_task用法及代碼示例
- Python Tkinter asksaveasfile()用法及代碼示例
- Python asyncio.Task.cancel用法及代碼示例
- Python ast.alias用法及代碼示例
- Python asyncio.loop.run_in_executor用法及代碼示例
- Python ast.Slice用法及代碼示例
- Python asyncio.Server用法及代碼示例
- Python asyncio.Server.serve_forever用法及代碼示例
- Python unittest assertIs()用法及代碼示例
- Python ast.NamedExpr用法及代碼示例
注:本文由純淨天空篩選整理自Arthur Yanagisawa大神的英文原創作品 Python | ascii method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。