Python * and * *

Source: Internet
Author: User
Tags function definition

* Two multiplication sign is the exponentiation, such as 2**4, the result is 2 4 times, the result is 16
A multiplication sign *, if the operand is two digits, which is the two numbers multiplied, such as 2*4, the result is 8
* If a string, list, tuple is multiplied by an integer n, returns a homogeneous object with all its elements repeating n times, such as "str" to return the string "Strstrstr"

If the * in front of the parameter in the function definition is represented by placing multiple parameters on the call into a tuple, * * means that the keyword argument when the function is called is placed in a dictionary
For example, define the following function
def func (*args):p rint (args)
Parameter args is a tuple (all-in-one) when calling a function with Func
Define the following functions

def func (**args):p rint (args)
When the function is called with func (a=1,b=2), the parameter args will be the dictionary {' A ': 1, ' B ': 2}

If it is in a function call, *args means that an iterative object is extended to the argument list of the function
Args= (a)
Func= (*args)
Equivalent to function call Func (+/-)
The * * Representation of a function call expands the dictionary to a keyword parameter
Args={' A ': 1, ' B ': 2}
Func (**args)
Equivalent to function call func (a=1,b=2)

Add Buckle group 813622576 We exchange study, send free information OH!!!!!

Python * and * *

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.