Python function (def)

Source: Internet
Author: User

function (Def)

function is to give a program a name, use the name to execute a program, repeated use.

Keyword ' def ' to define, identifier (parameter)

Examples of function use:

1.

Def boy ():

Print ("Hi,world")

The above function is relatively simple, run this function, just print out the Hi,world

2.

Def boy (A, b):

C=a+b

Return C

Above this function, after running, if given two values, that is, the two values are added, and the return value

3.

Def boy (Str,times):

C=str * Times

Return C

Above this function, given a string, and a number, that is, returning the corresponding number

4.

def boy (str, times= 1):

C=str * Times

Return C

Above this function, there is a default value of 1, if there is no value to the function, he defaults to output 1 times

5.

Def boy (a,b=2,c=9)

Print (A,B,C)

Boy (111,21)

Boy (54,c=8)

Boy (k)

Run the above function to define multiple default values

Python function (def)

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.