Calling functions
Python has many built-in functions that can be viewed in its pipe network document: https://docs.python.org/2/library/functions.html
The Help information can also be viewed at the command line in the case where the function name is known. For example, in Python, the absolute value of the function abs, can be viewed through Help (ABS) information on ABS
When calling the function, if the number of arguments passed is incorrect, the TypeError error will be reported, and Python will clearly indicate that the method has several parameters and passed several parameters, such as: The ABS method parameters only one, but if used to pass two parameters, such as ABS (1, 2), you will get the following errors,
Typeerror:abs () takes exactly one argument (2 given)
And if the number of arguments is correct but the type is not correct, you will get typeerror error message, prompt the wrong data type, such as: to ABS () into the string, shaped like abs (' a '), you will get the following error,
Typeerror:bad operand type for abs (): ' Str '
The comparison function cmp (x, y) requires two parameters, X<y, returns -1;X=-Y, returns 0;x>y, returns 1
In addition, Python's commonly used built-in functions also have type conversion functions, which are basically directly represented by a function name with the same name as the data type, such as:
>>> Int (' 123 ') 123>>> Int (12.34) 12>>> float (' 12.34 ') 12.34>>> str (1.23) ' 1.23 ' >>> Unicode (+) U ' >>> bool (1) true>>> bool (") False
It is important to note that the function name is actually a reference to a function object, it is possible to assign a function name to a variable, which is equivalent to giving the function an alias (which reminds us of the naming rules in the database), such as:
>>> a = ABS # variable a points to ABS function >>> A (-1) # So you can also call the ABS function by a 1
Python Self-study note function 1