Example analysis of return statement usages in Python

Source: Internet
Author: User
The example in this article describes the use of return statements in Python. Share to everyone for your reference. Specific as follows:

Return statement:

The return statement is used to return a function from a function. We can also choose to return a value from the function.

Use a literal statement

#!/usr/bin/python# Filename:func_return.pydef Maximum (x, y):  if x > y:    return x  else:    return yprint Maximum (2, 3)

Output

$ python Func_return.py3

Working principle:

The maximum function returns the maximum value in the parameter, which is the number provided to the function. It uses the simple if: Else statement to find a larger value, and then return that value.

Note that a return statement with no return value is equivalent to return none. None is a special type of Python that represents nothing. For example, if a variable has a value of none, you can indicate that it has no value.

Unless you provide your own return statement, each function contains a return none statement at the end. By running print someFunction (), you can see that the function someFunction does not use the return statement as follows:

Def someFunction ():  Pass

The pass statement represents an empty block of statements in Python.

Hopefully this article will help you with Python programming.

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