digital conversion of the number or type of python

Digital Type:

Integer (int) and floating point (float)

int (integer):

Role: preserving digital data types, such as phone number, qq number

1: Definition Method:

=. 17 Age    # Age = int (18 is) 

#int ( '1.1') can turn int # pure digital string of even a decimal point can not be transferred, so even if the type should be converted to a digital floating point type

 

2: binary conversion:

Decimal turn the other band:

Binary Decimal turn:

Print (bin (12 is ))

 ----------------------- 
>>> 0b1100     # 0B is identified, ob behind the figures is representative of a binary number

 

Octal, decimal turn:

print (oct (12)) # 0o14 0o on behalf of the latter figure is octal

Decimal convert hexadecimal:

print (hex (12)) # 0xc 0x behind the figures are representative of a hexadecimal number

Other band turns 10 hex:

# Convert 1100 This binary number to a decimal number:

  Print (int ( ' 1100 is ' , 2)) # int can pass the first parameter, the second parameter represents a parameter band what
 
  ----------- 
  >>> 12

 

And so on:

Octal, hexadecimal can use this method:

print ( '1100', 8) # octal, decimal turn

print ( '1100', 16) # decimal from hexadecimal

 

Guess you like

Origin www.cnblogs.com/pscly/p/11127830.html