bin(5) # '0b101'
oct(5) # '0o5'
hex(5) # '0x5'
int('110',2) # 6
int('110',8) # 64+8=72
int('110', 16) # 16*16+16=272
eg. 123 => [1, 2, 3]
a = 123
b = str(a) #'123'
c = list(b) #['1','2','3']
d = list(map(int,c)) #[1, 2, 3]
eg. [1,2,3] => 123
a = [1,2,3]
b = list(map(str,a)) # ['1', '2', '3']
c = ''.join(b) # '123'
d = int(c) # 123
In the computer, the calculation is performed in the form of two's complement,5的是正數,補碼等於原碼:0000 0000 0000 0000 0000 0000 0000 0101
, 取非後:1111 1111 1111 1111 1111 1111 1111 1010
, Computer operations are performed in two's complement form,However, it is still displayed in the original form on the terminal,Convert the result back to the original code(補碼的補碼,Complementing a negative number is adding the inverse1):1000 0000 0000 0000 0000 0000 0000 0110
, 也就是-6
.
chr(97) #'a'
ord('a') # 97
numbers=[0,0,3,4]
for i,num in enumerate(numbers):
print(i, num)
0 0
1 0
2 3
3 4
分別是index, 和值