Example Analysis of return Statement usage in Python and python instance analysis

Source: Internet
Author: User

Example Analysis of return Statement usage in Python and python instance analysis

This example describes the return statement usage in Python. Share it with you for your reference. The details are as follows:

Return Statement:

Return statements are used to jump out of a function when a function is returned. We can also return a value from the function.

Use literal statements

#! /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 value in the return parameter of the maximum function. Here it is the number provided to the function. It uses a simple if... else statement to find a large value and then return that value.

Note that a return statement without a return value is equivalent to return None. None is a special type in Python that indicates nothing. For example, if the value of a variable is None, it indicates 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 understand this. The someFunction does not use the return statement, as shown below:

Def someFunction (): pass

The pass statement indicates an empty statement block in Python.

I hope this article will help you with Python programming.

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.