ITPub博客

首页 > 应用开发 > > 简单爬虫原理笔记第二章练习题7

简单爬虫原理笔记第二章练习题7

作者:zhuyg 时间:2019-08-27 17:18:00 0 删除 编辑

#习题7,下面两段代码输出是什么

class Person:

name = "aaa"

p1 = Person()

p2 = Person()

p1.name = "bbb" #因为作用在这里有个新的变量,所以第一个输出的是bbb

print (p1.name)

print (p2.name)

print (Person.name)

bbb

aaa

aaa

class Person:

name = [] #对象为list与dict是可变的,可以更改

p1 = Person()

p2 = Person()

p1.name.append(1)

print (p1.name)

print (p2.name)

print (Person.name)

1

1

1

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/861/viewspace-3156014/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    115
  • 访问量
    1101