只是为一个项目研究python中的数据结构,无法找出字典和这种形式的数据结构的区别:
class Address:
def __init__(self, house_number, house_street, house_city,
house_county, house_postcode):
self.number = house_number
self.street = house_street
self.city = house_city
self.county = house_county
self.postcode = house_postcode
def __repr__(self):
return ('<Class: \'Address\', '+ str(self.number) + ' ' +
self.street + ' ' + self.city + ' ' +
self.county + ' ' + self.postcode + '>')
## Creates an object Address and assign it to a variable
my_address = Address(1, 'abc', 'def', 'ghi', 'jkl')
## Print the object My_address
print 'Address object:', my_address
print 'house number:', my_address.number
## change house number
my_address.number = 555
print 'NEW house number:', my_address.number
代码示例是从约克大学讲座中给出的示例代码修改而来的。