Class


In [ ]:
class MyClass(object):
    pass

In [ ]:
MyClass()

In [ ]:
myclass = MyClass()

In [ ]:
myclass

In [ ]:
myclass01 = MyClass()

In [ ]:
print(id(myclass))
id(myclass01)

In [ ]:
myclass.attri01 = 5
myclass.attri02 = "attri 02"

In [ ]:
print(myclass.attri01)
print(myclass.attri02)

In [ ]:
myclass01.attri01

In [ ]:
class MyClass(object):
    attri01 = 4
    
    pass

In [ ]:
myclass02 = MyClass()

In [ ]:
myclass02.attri01

In [ ]:
myclass02.attri01 = 6

In [ ]:
myclass02.attri01

In [ ]:
myclass03 = MyClass()

In [ ]:
myclass03.attri01

In [ ]:
MyClass.attri01

In [ ]:
class MyClass(object):
    
    def __init__(self):
        self.attri01 = 7
        self.attri02 = "attri 02"
        self.attri03 = []
        print(self, "is create")

In [ ]:
myclass = MyClass()

In [ ]:
myclass01 = MyClass()

In [ ]:
print(myclass.attri01)
print(myclass.attri02)
print(myclass.attri03)

print(myclass01.attri01)
print(myclass01.attri02)
print(myclass01.attri03)

In [ ]:
myclass.attri01 += 1

In [ ]:
print(myclass.attri01)
print(myclass01.attri01)

In [ ]:
class MyClass(object):
    
    classAttr = "this is class attri"
    
    def __init__(self):
        self.attri01 = 7
        self.attri02 = "attri 02"
        self.attri03 = []
        print(self, "is create")

In [ ]:
myclass = MyClass()
myclass01 = MyClass()

In [ ]:
MyClass.classAttr

In [ ]:
myclass.classAttr = "this is obj attri"

In [ ]:
print(myclass.classAttr)
print(myclass01.classAttr)

In [ ]:
myclass02 = MyClass()

In [ ]:
myclass02.classAttr

In [ ]:
class MyClass(object):
    
    InstanceCount = []
    
    def __init__(self):
        self.attri01 = 7
        self.attri02 = "attri 02"
        self.attri03 = []
        print(self, "is create")
        
        MyClass.InstanceCount.append(self)

In [ ]:
myclass = MyClass()
myclass01 = MyClass()
myclass02 = MyClass()
myclass03 = MyClass()

In [ ]:
MyClass.InstanceCount

In [ ]:
del MyClass.InstanceCount[0]

In [ ]:
myclass

In [ ]:
# --------------------------------------------------------------------------------  
# Copyright (c) 2013 - 2014 Mack Stone. All rights reserved.  
#   
# Permission is hereby granted, free of charge, to any person obtaining a copy  
# of this software and associated documentation files (the "Software"), to deal  
# in the Software without restriction, including without limitation the rights  
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
# copies of the Software, and to permit persons to whom the Software is  
# furnished to do so, subject to the following conditions:  
#   
# The above copyright notice and this permission notice shall be included in  
# all copies or substantial portions of the Software.  
#   
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  
# THE SOFTWARE.  
# --------------------------------------------------------------------------------