没对象?没关系,new一个,赶紧来测试下自己new的技术如何吧。
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) Person('林小花',18)
请直接说出上面代码结果及原因:
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.__country)
请直接说出上面代码结果及原因:
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.age)
请直接说出上面代码结果及原因:
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.__name)
请直接说出上面代码结果及原因:
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.query()
请直接说出上面代码结果及原因:
class Person(object): __country = 'China'
def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.__query()
请直接说出上面代码结果及原因:
class Person(object): __country = 'China' def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*')) def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query() def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.__country = 'America' print("你女朋友的国籍是:",gf.__country) gf.query() print(gf._Person__country) gf._Person__country = 'America2' print("你女朋友的国籍是:",gf.__country) gf.query() print(gf._Person__country)
请直接说出上面代码结果及原因:
class Person(object): __country = 'China' def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*')) def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query() def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.__name = 'Lili' print("你女朋友的名字是:",gf.__name) gf.query() print(gf._Person__name) gf._Person__name = 'Lili2' print("你女朋友的名字是:",gf.__name) gf.query() print(gf._Person__name)
请直接说出上面代码结果及原因:
提前祝君七夕happy。
图片来源于网络,如有侵权,请联系删除。