Python local variables and global variables

Source: Internet
Author: User

Learning Source: http://www.cnblogs.com/alex3714/articles/5885096.html
‘‘‘
School = "Old boy"
def change (name):
Global School #函数内修改全局变量
School = "Wo de"
#name = ' Li ' #这个函数就是这个变量的作用域
# print (name)
Name= ' Alx '
Change (name)
Print ("hhh%s"%school)


#在函数里改一个局部变量, the function is called and there is no way to know where the variable was changed.
# Back and forth calls can cause confusion in function logic, only a global variable outside is still viable
Def chang_name ():
Global Name
name = "Alx"
chang_name ()
print (name)
#字符串与单独的整数不能在函数中 Modified values, lists, dictionaries, collections, classes, etc. this complex data can be changed within the function
names =[ def change_name ():
Names[0]= "DA"
print (names)
Change_name ()
Print (names)

Python local variables and global variables

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.