我收到一个错误“ NameError:未定义名称'first_name'”。
narek = {
"first_name": "Narek",
"last_name": "Kuloyan",
"age": 27,
"city": "Yerevan",
}
…
people = [narek, tigran, karen]
for mard in people:
for tvyal, info in mard.items():
anun = info[first_name] + info[last_name]
print("Anun azganun: "+ anun.title())
print("\nTariq: " + str(info[age]))
答案 0 :(得分:0)
如果我正确理解了您期望实现的目标,那么这段代码就可以完成工作。
narek = {
"first_name": "Narek",
"last_name": "Kuloyan",
"age": 27,
"city": "Yerevan",
}
people = [narek]
for mard in people:
anun = mard['first_name'] + mard['last_name']
print("Anun azganun: "+ anun.title())
print("\nTariq: " + str(mard['age']))