现在的位置: 首页 > 综合 > 正文

004_018 Python 添加 修改一系列已经命名的参数 用于搜集一系列元素,然后重命名

2017年12月10日 ⁄ 综合 ⁄ 共 311字 ⁄ 字号 评论关闭

代码如下:

#encoding=utf-8

print '中国'

#添加 修改一系列已经命名的参数 用于搜集一系列元素,然后重命名

#每个类都有一个内置的字典
class bunch(object):
    def __init__(self,**kwds):
        self.__dict__.update(kwds)


x=10
y=120
threshold=140

setitems=bunch(data=y,squared=y*y,coord=x)

if setitems.squared > threshold:
    print x
    
y=1

setitems.squared=10

if setitems.squared < threshold:
    print x
    

打印结果如下:

中国
10
10

抱歉!评论已关闭.