用法:
oct(x)
將整數轉換為前綴為 “0o” 的八進製字符串。結果是一個有效的 Python 表達式。如果
x
不是 Pythonint
對象,則它必須定義一個返回整數的__index__()
方法。例如:>>> oct(8) '0o10' >>> oct(-56) '-0o70'
如果要將整數轉換為帶有前綴 “0o” 的八進製字符串,可以使用以下任一方法。
>>> '%#o' % 10, '%o' % 10 ('0o12', '12') >>> format(10, '#o'), format(10, 'o') ('0o12', '12') >>> f'{10:#o}', f'{10:o}' ('0o12', '12')
另請參閱
format()
了解更多信息。
相關用法
- Python oct()用法及代碼示例
- 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.path.splitdrive用法及代碼示例
- Python os.mkdir()用法及代碼示例
- Python os.close()用法及代碼示例
- Python os.chroot()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 oct。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。