Python type digital learning ----

A: int type

1. Definitions:

age = 10 # age=int(10)

2. name (parameters)

rint('hello','world')

x=int(10)
name=input('xxx')
res=print('xxx') # 没有产品
print(res)

3, type conversion

3.1 pure digital converted into a string of int

res=int('100111')
print(res,type(res))

3.2 (understand)

3.2.1 turn into other binary decimal

10进制 -> 二进制
11 - > 1011
1011-> 8+2+1
print(bin(11)) # 0b1011

10进制 -> 八进制
print(oct(11)) # 0o13

10进制 -> 十六进制
print(hex(11)) # 0xb
print(hex(123)) # 0xb

2.2.2 Other converted to its decimal system

二进制->10进制
print(int('0b1011',2)) # 11

二进制->8进制
print(int('0o13',8)) # 11

二进制->16进制
print(int('0xb',16)) # 11

Two: float type

1. purely digital string into int, not including the decimal point

res = int('100111') 
print(res,type(res))

100111 <class 'int'>

2. Base conversion (to know)

Decimal -> binary: In addition modulo 2

11 —> 1011

Binary -> 10 hex: 8421 method

1011 —> 11

Decimal converted to other binary:

Python can be used "bin ()" is converted to the binary decimal

print(bin(11))

0b1011

Can be used in Python "oct ()" is converted to the decimal octal

print(oct(11))

0o13

Can be used in Python "hex ()" is converted to the hex 10 hex

print(hex(11))

0xb

3: Use

int and float do not need to have built-in methods of their use is relatively math operations +

Guess you like

Origin www.cnblogs.com/x945669/p/12458505.html