在本教程中,我們將借助示例了解 Python ord() 函數。
ord()
函數返回一個表示 Unicode 字符的整數。
示例
character = 'P'
# find unicode of P
unicode_char = ord(character)
print(unicode_char)
# Output: 80
ord() 語法
用法:
ord(ch)
參數:
ord()
函數采用單個參數:
- ch- 一個 Unicode 字符
返回:
ord()
函數返回一個表示 Unicode 字符的整數。
示例:ord() 如何在 Python 中工作?
print(ord('5')) # 53
print(ord('A')) # 65
print(ord('$')) # 36
輸出
53 65 36
順便說一句,ord()
函數是 Python chr() function 的逆函數。
相關用法
- Python ord()用法及代碼示例
- Python os.path.normcase()用法及代碼示例
- Python os.read()用法及代碼示例
- Python os.DirEntry.inode()用法及代碼示例
- Python os.closerange()用法及代碼示例
- Python os.set_blocking()用法及代碼示例
- Python os.pathconf()用法及代碼示例
- Python os.chflags()用法及代碼示例
- Python operator.truth()用法及代碼示例
- Python operator.le()用法及代碼示例
- Python os.WCOREDUMP()用法及代碼示例
- Python os.fork()用法及代碼示例
- Python os.ctermid()用法及代碼示例
- Python os.mkfifo()用法及代碼示例
- Python os.tcsetpgrp()用法及代碼示例
- Python os.path.commonpath()用法及代碼示例
- Python os.mkdir()用法及代碼示例
- Python os.close()用法及代碼示例
- Python os.chroot()用法及代碼示例
- Python os.path.expanduser()用法及代碼示例
注:本文由純淨天空篩選整理自 Python ord()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。