python data type

1. Numbers

int (integer)

  On a 32-bit system, the number of digits of an integer is 32 bits, and the value range is -2**31 to 2**31-1, that is, -2147483648 to 2147483647.
  On a 64-bit system, the number of digits of an integer is 64 bits. The value range is -2**63~2**63-1, that is -9223372036854775808~9223372036854775807
 
long (long integer)

  Python's long integers do not have a specified bit width, but in fact, due to limited machine memory, the long integer values ​​we use cannot be infinitely large.
  Since Python 2.2, if the integer overflows, Python will automatically convert the integer data to a long integer, so now it will not cause serious consequences without the letter L after the long integer data.
       

        The python2.7 version is used in this figure, type(2**16) and type(2**25) are int integers, but type(2**32) automatically becomes long long integers

float
 
  Floating point numbers are used to deal with real numbers, i.e. numbers with decimals. Similar to the double type in C language, it occupies 8 bytes (64 bits), of which 52 bits represent the base, 11 bits represent the exponent, and the remaining one represents the sign.
        1 print(type(0.000523)) 2 print(5.23E-4) 3 print(5.23*10**-4) 
       result
       

 

complex (plural)

  A complex number consists of a real part and an imaginary part. The general form is x+yj, where x is the real part of the complex number and y is the imaginary part of the complex number, where both x and y are real numbers. use less
       Note: There is a small number pool in Python: -5 to 257
 
2. Boolean value
 
  true or false, 1 or 0
1 a = 0
2 if a :
3     print("true")
4 else:
5     print("flase")

       Returns flase when a is equal to 0, and returns true when a is equal to 1

 
3. String
 
      string
      Text in python is always encoded in unicode, represented by str type;
 
4.bytes type
 
      binary type
      String and binary types are the same in python2, and in python3, a clearer distinction is made between text and binary data.
      Text is always encoded in unicode, represented by type str; binary data is represented by type bytes.
 
      In python3, you cannot mix the two types str and bytes in any implicit way. You can't concatenate str and bytes types, you can't search for bytes data in str (and vice versa), and you can't pass str as a parameter to a function that expects a bytes-type parameter (and vice versa).
 

      Strings can be encoded into bytes, and bytes can also be decoded into strings:

1 >>> '€20'.encode('utf-8')
2 b'\xe2\x82\xac20'
3 >>> b'\xe2\x82\xac20'.decode('utf-8')
4 '€20'
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325293821&siteId=291194637