我正在用 python 学习 OOP。我想实现类似显示:
firstName
,lastName
地址为字典之类的人,'state': someState, 'city': someCity
我弄完了:
class data:
def __init__(self, firstName, lastName, **address):
self.firstName = firstName
self.lastName = lastName
self.address = {
"state": self.state,
"city" : self.city
}
当我这样做时:
>>> d = data("a", "b", 'state' : "stat", 'city' : "ci")
SyntaxError: invalid syntax
>>> d = data("a", "b", 'state'="stat", 'city'="ci")
SyntaxError: keyword can't be an expression
我的代码是否有错误或访问字典的语法有误。我想不明白。