• Python: 3.8.11
  • OS: Ubuntu Kylin 20.04
  • Conda: 4.10.1
  • Jupyter lab: 3.1.4

Code sample

# binary
bin_num = 0b111
# octal
oct_num = 0o011
# a decimal
int_num = 100
# hex
hex_num = 0xf
Copy the code
# output (decimal)
print(bin_num)
print(oct_num)
print(int_num)
print(hex_num)


7
9
100
15
Copy the code
# 2 to 8 10 16
bin_num = 0b111
print(oct(int(str(bin_num))))
print(int(bin_num))
print(hex(int(str(bin_num))))


0o7
7
0x7
Copy the code
# 8 to 2 10 16
oct_num = 0o011
print(bin(int(str(oct_num))))
print(int(oct_num))
print(hex(int(str(oct_num))))


0b1001
9
0x9
Copy the code
# 10 to 2 8 16
int_num = 15
print(bin(int_num))
print(oct(int_num))
print(hex(int(str(int_num))))


0b1111
0o17
0xf
Copy the code
# 16 to 8 10
hex_num = 0xff
print(bin(hex_num))
print(int(hex_num))
print(oct(int(str(hex_num))))


0b11111111
255
0o377
Copy the code

Learning to recommend

  • Python documentation – English
  • Python documentation – Chinese
  • Python code PEP
  • Google version of the Python specification
  • Python source code
  • Python PEP
  • Optimal kirin
  • The nuggets platform
  • Gitee platform


Python is open source, cross-platform, interpretive, interactive, and worth learning. Python’s design philosophy: elegant, unambiguous, simple. Advocate one way, preferably only one way to do one thing. Code should be written in accordance with specifications to facilitate communication and understanding. Every language has its own unique ideas. Beginners need to change their thinking, practice and accumulate.