tutorial on using instances of the Apply function in Python

Source: Internet
Author: User
First, overview:

The specific meanings of the Python apply function are as follows:

the Apply (func [, args [, Kwargs]]) function is used to indirectly invoke a function when a function parameter already exists in a tuple or dictionary . Args is a tuple that contains the arguments passed by position that will be supplied to the function. If args is omitted, no arguments are passed, and Kwargs is a dictionary containing the keyword arguments.

The return value of apply () is the return value of the Func (), and the element parameters of apply () are ordered, and the order of the elements must match the order of the Func () Form parameters

Second, use example:

Here are a few examples to explain the use of apply in detail:

1. Assume that a method with no parameters is executed:

Def say (): print ' say in ' Apply (say)

The result of the output is ' say in '

2. The function only takes the parameters of the tuple:

Def say (A, b): Print A, b apply (say, ("Hello", "Zhang San Python"))

The result of the output is Hello, Zhang San python

3. Function with keyword parameter:

def say (a=1,b=2): Print a, b def haha (**kw): #say (kw) apply (say, (), kw) print haha (a= ' a ', b= ' B ')

The result of the output is: A, b

  • 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.