Python function Chapter 0-2

Source: Internet
Author: User
Tags define function

There are three different parameters to the function:

  • General parameters
  • Default parameters
  • Dynamic parameters
    # ######### define function #########

    # name is called the formal parameter of function func, abbreviation: Parameter
    def func (name):
    Print (name)

    # ######### Execute function #########
    # ' Fuyuteng ' is called the actual argument of function func, abbreviation: argument
    Func (' Fuyuteng ')

     def func (name, age = 18print (" %s:%s (name,age)) # specify parameter func ( ' fuyuteng ", 19) # Use default parameter func (
  • def func (*args):    print (args) dynamic parameter-sequence # execution Mode one func (11,33,4,4454,5)#  Execution mode Two li = [11,2,2,3,3,4,54]func (*li)        
  • Dynamic Parameters-Dictionary
  • def func (* *kwargs): print (args) Span style= "COLOR: #008000" ># execution mode one func (Name= "fuyutengi ", Age=18) # execution mode two li = {" name ": " fuyuteng", age:18,  ' gender":  ' male< Span style= "COLOR: #800000" > ' }func (**li)        
  • < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" > dynamic parameters-sequence and dictionary
  • def func (*args, * *Kwargs):    print (args)    print (Kwargs)   

Python function Chapter 0-2

Related Article

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.