Python 3.5 (11) function

Source: Internet
Author: User

Functional programming The most important thing is to enhance the reusability and readability of code

Ii. Definition and use

def 函数名(参数):  

     ...      函数体      ...

The definition of a function has the following main points:

    • def: A keyword that represents a function
    • Function name: the names of functions, which are called later by function name
    • Function Body: A series of logical calculations in a function, such as sending a message, calculating the maximum number in [11,22,38,888,2], etc...
    • Parameters: Providing data for the function body
    • Return value: Once the function has finished executing, it can return data to the caller.

In the above points, it is more important to have parameters and return values:

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: formal parameter  def   func (name):  print   name  #   ######### Execute function #########  #   func ( " Span style= "COLOR: #800000" >wupeiqi   " ) Normal parameters  
    def func (name, age =):        print"%s:%s" %(name,age)  #  Specify parameter func ('wupeiqi', +)#  Use default parameter func ('Alex') Note: Default parameters need to be placed at the end of the parameter list

Python 3.5 (11) function

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.