正在加载图片...
元组 ·元组:用圆括号包围的一组值 一类似列表但内容不可修改 一例如:创建计算器按钮的代码: bSpecs=[(2,1,'0),(3,1,'.), (1,2,1),(2,2,2),(3,2,3),(4,2,+),(5,2,’-) (1,3,4),(2,3,5),(3,3,6),(4,3,*),(5,3,1), (1,4,7),(2,4,8),(3,4,9),(4,4<-),(5,4,C)] self.buttons =[ for(cx,cy,label)in bSpecs: self.buttons.append(Button(self.win,Point(cx,cy),.75,.75,label)) create the larger'='button self.buttons.append(Button(self.win,Point(4.5,1),1.75,.75,"=") Lu Chaojun,SJTU 13元组 • 元组:用圆括号包围的一组值. – 类似列表但内容不可修改. – 例如:创建计算器按钮的代码: bSpecs = [(2,1, ’0’), (3,1, ’.’), (1,2, ’1’), (2,2, ’2’), (3,2, ’3’), (4,2, ’+’), (5,2, ’-’), (1,3, ’4’), (2,3, ’5’), (3,3, ’6’), (4,3, ’*’), (5,3, ’/’), (1,4, ’7’), (2,4, ’8’), (3,4, ’9’), (4,4, ’<-’),(5,4, ’C’)] self.buttons = [] for (cx,cy,label) in bSpecs: self.buttons.append(Button(self.win,Point(cx,cy),.75,.75,label)) # create the larger ’=’ button self.buttons.append(Button(self.win, Point(4.5,1), 1.75, .75, "=")) Lu Chaojun, SJTU 13
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有