现在我知道已有一些关于这个主题的报道,但我无法理解.我会告诉你我的代码,我希望这能帮助你了解我的目标.
字典
father = {"Yin": ["yang","yaha"]}
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常.
elif choice == "5":
son = input("Enter the name of a son to get the name of his grandfather: ")
if son in father:
description = father[son]
print("\n", son, "'s grandfather is", description[1])
else:
print("\nSorry, I don't know who that is", son)
Run Code Online (Sandbox Code Playgroud)
这段代码没有,我只是希望它能够更改列表中的第二项(yaha).
elif choice == "6":
son = input("which grandfather and son pair need updating: ")
if son in father:
description = input("What's name of the grandfather?: ")
son[father] = description[1]
print("\n", …Run Code Online (Sandbox Code Playgroud) python ×1