Python ord() 函數(shù)

2019-03-13 13:44 更新

Python ord() 函數(shù)

Python 內(nèi)置函數(shù) Python 內(nèi)置函數(shù)

描述

Python ord() 函數(shù)是 chr() 函數(shù)(對于8位的ASCII字符串)或 unichr() 函數(shù)(對于Unicode對象)的配對函數(shù),它以一個字符(長度為1的字符串)作為參數(shù),返回對應的 ASCII 數(shù)值,或者 Unicode 數(shù)值,如果所給的 Unicode 字符超出了你的 Python 定義范圍,則會引發(fā)一個 TypeError 的異常。

語法

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

ord(c)

參數(shù)

  • c:字符。

返回值

返回值是對應的十進制整數(shù)。

實例

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

>>>ord('a')
97
>>> ord('b')
98
>>> ord('c')
99

Python 內(nèi)置函數(shù) Python 內(nèi)置函數(shù)

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號