Python3 ascii() 函數

Python3 內置函數 Python3 內置函數


描述

ascii() 函數類似 repr() 函數, 返回一個表示對象的字串, 但是對於字串中的非 ASCII 字元則返回通過 repr() 函數使用 \x, \u 或 \U 編碼的字元。 生成字串類似 Python2 版本中 repr() 函數的返回值。


語法

以下是 ascii() 方法的語法:

ascii(object)

參數

  • object -- 對象。

返回值

返回字串。


實例

以下展示了使用 ascii() 方法的實例:

>>> ascii('zaixian')
"'zaixian'"

Python3 內置函數 Python3 內置函數