import copy
class Employee:
age = 10
employee_name = 'zxc'
class Company:
name = ''
num = 0
def __init__(self, name):
self.name = name
def set_num(self, num):
self.num = num
def set_employee(self, age, employee_name):
self.age = age
self.employee_name = employee_name
def show_data(self):
print self.employee_name
print self.age
print self.name
print self.num
def clone(self):
return self
if __name__ == "__main__":
com = Company("紫极")
com_clone = com.clone()
com.set_num(123)
com_clone.set_num(456)
com.set_employee("张三", 2011)
com_clone.set_employee("李四", 2012)
com.show_data()
com_clone.show_data()
com_copy = copy.copy(com)
com_deepcopy = copy.deepcopy(com)
com_copy.set_num(999)
com_deepcopy.set_num(88888)
com_copy.set_employee("张飞", 5656)
com_deepcopy.set_employee("宋江", 8282)
com_copy.show_data()
com_deepcopy.show_data()
深拷贝和浅拷贝的对象地址不一样