Python's object-to-class data properties combined with data attributes of an instance-no naming look, you're not crazy. Series

Source: Internet
Author: User

1.

classChinese:country=' China'    def __init__(self,name): Self.name=namedefPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball)) P1=chinese ("North Sir")Print(P1.country)#This is the data property of the class accessedp1.country="Japanese"#added data properties for an instancePrint(Chinese.country)#invoking the data properties of a classPrint(P1.country)#The Data property of the instance is invoked because the country property of the instance is increased above the JapaneseC:\python35\python3.exe D:/pyproject/day24/class properties are combined with instance properties. Pychinachina Japanese

2.

classChinese:country='China'    def __init__(self,name):Print("Instantiate First run init------->") Self.name=namedefPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball))defShi_li_hua ():#defining an instantiation functionName=input (">>>")#accept a value assignment to nameP1=chinese (name)#instantiate a P1 instance    Print(P1.country)#The data property of the class that invokes the instanceShi_li_hua ()#run Shilihua This function, front is defined, put those loaded into memory, this is the first step of the program run, and then rheumatism theory up, scope

3.

country="China"classChinese:country='China + + +'    def __init__(self,name): Self.name=namePrint("---->", country)#This country is not used. Called, neither the property of the class nor the attribute of the instance, is a common variable, following the rheumatism theory    defPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball)) P1=chinese ("North Sir")#instantiate a P1 instanceC:\python35\python3.exe D:/pyproject/day24/class properties are combined with instance properties. PY----> China

4.

country="China + +"classChinese:country='China'    def __init__(self,name): Self.name=namePrint("Common Variables", country)#This country is not used. Called, neither the property of the class nor the property of the instance, is a normal variable    defPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball))Print(country)#calling the global scope of countryPrint(Chinese.country)#the Data property of the calling class countryP1=chinese ("North Sir")#instantiate a P1 instancePrint(P1.country)#The data property of the class that invokes the instance, not in the instance dictionary, goes to the class dictionary to findC:\python35\python3.exe D:/pyproject/day24/class properties are combined with instance properties. PY China++China common variable china++China

5.

classChinese:country=' China'L=["a","b"]#the attribute Dictionary of the existence class    def __init__(self,name): Self.name=namedefPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball)) P1=chinese ("North Sir")Print(P1.L)#instance P1 calling the class's Data property Lp1.l=[1,2,3]#Add a Data attribute L to the instance P1, there is a P1 attribute dictionary insidePrint(CHINESE.L)#invoking the data properties of a classPrint(P1.L)#invoking the data properties of an instanceC:\python35\python3.exe D:/pyproject/day24/you're in a different position. py['a','b']['a','b'][1, 2, 3]

6.

classChinese:country=' China'L=["a","b"]#the attribute Dictionary of the existence class    def __init__(self,name): Self.name=namedefPlay_ball (self,ball):Print('%s is playing%s'%(Self.name,ball)) P1=chinese ("North Sir")Print(P1.L)#instance P1 calling the class's Data property LP1.l.append ("C")#adds a C to the data property of the class called by the instancePrint(CHINESE.L) C:\python35\python3.exe D:/pyproject/day24/you're in a different position. py['a','b']['a','b','C']

Python's object-to-class data properties combined with data attributes of an instance-no naming look, you're not crazy. Series

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.