I love the difference between Python's *arges and **kwarges.

Source: Internet
Author: User

1. * and * * in function call:*: Tuple or list "appears" * *: Dictionary "haunt" >>>defCheck_web_server (host, Post, path): Host_info = (' www.python.org ', 80, '/') when invoked: Check_web_server (host_info[ 0], host_info[1], host_info[2])This type of writing is neither amplified (a dozen parameters) nor is it difficult to seeWhen using the * Number: Check_web_server (*host_info)Clean and elegantWhen host_info = {host= ' www.python.org ', post=80, path= '/'} with **:check_web_server (**host_info)key names to match 2. * and * * in function definition:Allows Python to support variable-length parameters, which can receive any number of parameters >>>defDaily_sales_total (*all_sales): total = 0.0 for Each_sale in all seles:total + = Float (each_sale) return total >>> daily_sales_total () >>> daily_sales_total (0.0) >>> Daily_sales_total (1.0, 2.0, 3.0) >>>defCheck_web_server (host, post, Path, *args, **kwargs): # This function must accept at least three initial parameters, and can accept any subsequent number of arguments or keyword arguments

I love the difference between Python's *arges and **kwarges.

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.