Simple notation for functions

Source: Internet
Author: User

Writing rules for functions:

def function name (parameter):
function body
return value

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 in the future according to the function name (similar to a variable)
  • function Body: The function of a series of logical calculations, such as: The received data must be a number, to find the maximum value, etc...
  • Parameters: Providing data for the function body (providing one or more variables to the function)
  • Return value: Once the function has finished executing, it can return data to the caller.

1. Return value

A function is a function block, and the result of the execution of the function is to inform the caller by the return value

2. Parameters

# no parameters
def test1 ():
Print (123)
Test1 ()
# Default Parameters
def test1 (w= ' day1 '):
Print (W)
Test1 ()
# General Parameters
def test2 (W):
Print (W)
Test2 (2)
# Specify parameters
def test3 (w,e):
Print (w,e)
Test3 (e=2,w=1)
# any number of parameters
def test4 (*args):
Print (args)
Test4 (1,2,3,4,5,6)
# character Typical parameters
def test5 (**kwargs):
Print (Kwargs)
Test5 (name= ' Jack ', sex= ' nan ')

Simple notation for functions

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