[Python]Shallow and Deep copy operation

The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances).

import copy

class MyKlass(object):
    def __init__(self,name):
        self.name = name
    def test(self):
        print "this is " + self.name

class MyDict(dict):
    pass

def myFunction():
    print "this is function"


if __name__ == ‘__main__‘:
    k = type(MyKlass)
    print k    
    NewClass = copy.copy(MyKlass)
    NewClass("Python").test()
    d = type(MyDict)
    print d.__base__
    f = type(myFunction)
    print f.__name__


[Python]Shallow and Deep copy operation,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。