我是一个蟒蛇新手! 我正在上课,列表和字典,我有一个问题!
我有这段代码:
class Vacca( object ):
Munte = dict()
def __init__( self, nr ):
self.nome = "VACCA_" + str( nr )
self.numero = str(nr)
self.mungiture = []
def mungi( self, latte ):
nr = self.numero
Vacca.Munte[ nr ] = self
Vacca.Munte[ nr ].mungiture.append( latte )
vacca = Vacca( 1 )
vacca.mungi( "white milk" )
vacca = Vacca( 1 )
vacca.mungi( "black milk" )
vacca = Vacca( 1 )
vacca.mungi( "yellow milk" )
vacca = Vacca( 2 )
vacca.mungi( "dark chocolate" )
for v in Vacca.Munte:
print Vacca.Munte[v].mungiture
如果我运行这是结果:
['yellow milk']
['dark chocolate']
但我需要这个:
['white milk','black milk','yellow milk']
['dark chocolate']
我错了什么?