Python standard built-in functions and python type built-in functions
Python provides some built-in functions for basic object types: cmp (), repr (), str (), type () and ('') Operators equivalent to repr ().
(1) type ()
The usage of type is as follows:
Type (object)
Accept an object as a parameter and return its type. The returned value is a type object.
>>> Type ('R') <type 'str' >>>> type (3) <type 'int' >>>> type (5 )) <type 'type'>
(2) cmp ()
The built-in function cmp () is used to compare two objects, obj1 and obj2. If obj1 is greater than obj2, a positive integer is returned. If it is smaller than, a negative integer is returned. If it is equal to, 0 is returned.
>>> A, B = 4, 12 >>> cmp (a, B)-1 >>> B = 4 >>> cmp (a, B) 0 >>>, B = 'xyz', 'abc'> cmp (a, B) 23
(3) str (), repr ()
You can easily obtain the object content, type, numeric attributes, and other information in string mode. The str () function makes the string readable, while the string obtained by repr () can be used to obtain the object again.
>>> Str (1) '1' >>> str (2e4) '2017. 0' >>> repr ([20000,]) '[,]'