p**z 发帖数: 65 | 1 没人发帖好冷清。我来发几个平时用Python攒的小窍门吧。笔记是英文的懒得翻译了
Python tips: binary, octal, and hex numbers
To use literal values in binary, octal, or hex (works since Python 2.6):
binary: 0b1111
octal: 0o105
hex: 0xffff
To convert an input string that is the representation of a number in a
specific base to an integer:
int('1111', 2)
int('105', 8)
int('ffff', 16)
To output the string representation of a number in a specific base:
If converting to binary, numpy.binary_repr() is the most efficient
If converting to any base, numpy.base_repr() is the one to use |
|