The path to learning in Python--05 basic articles

Source: Internet
Author: User

In Python, there are also global variables and local variables, but as far as I know, if a variable defined in the if is a global variable that falls down, there is also a function definition and return in Python, usually defining a function:

def function name (parameter 1, parameter 2, ...) ):

function body

return x

Of course, no arguments are allowed, and if you do not write return, the default return is NULL, and the value of the global variable cannot be modified within the function, and if you want to assign a value to a global variable outside the function, you use the global statement to indicate that the variable is a global variable. Otherwise, it will go wrong. However, if you do not need to reassign a global variable, you may not use the global statement, but you can tell the person reading the code after using the global statement, which is already stated in the global variable.

# !/usr/bin/env Python 3.6 " -*-Coding:-utf8--*- " Num=10def  changnum ():    global  num    print( num)    num=100    print(num)    return  numPrint (Changnum ())

The path to learning in Python--05 basic articles

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.