How do I invoke a built-in function in Python? (Instance parsing)

Source: Internet
Author: User
For the first time a friend of the Python programming language, just beginning to learn Python programming for python function callThis aspect of the understanding is relatively small, in this article we will come to understand how Python calls functions

Python has built in a lot of useful functions that we can call directly.

To invoke a function , you need to know the name and parameters of the function, such as the function abs with absolute value, with only one parameter.

If you want to know the specific built-in function, you can view the document directly from the Python official website:

Http://docs.python.org/3/library/functions.html#abs

You can also view the Help information for the ABS function on the interactive command line by helping (ABS).

Call the ABS function:

>>> ABS (100>>>) ABS ( -20) 20>>> abs (12.34) 12.34

When calling a function, if the number of arguments passed in is incorrect, the TypeError error is reported, and Python will explicitly tell you that ABS () has only 1 parameters, but gives two:

>>> ABS (1, 2) Traceback (most recent):  File "<stdin>", line 1, in <module>typeerror:abs () takes exactly one argument (2 given)

If the number of arguments passed in is correct, but the parameter type cannot be accepted by the function, the TypeError error is reported, and an error message is given: STR is the wrong parameter type:

>>> ABS (' a ') Traceback (most recent call last):  File "<stdin>", line 1, in <module>typeerror:bad Operand type for abs (): ' Str '

The Max function Max () can receive any number of arguments and return the largest one:

>>> Max (1, 2) 2>>> Max (2, 3, 1,-5) 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.