为什么我的词典中出现语法错误?

问题描述 投票:-2回答:1
message = input(">")
words = message.split(' ')

emojis = {
    ":)": "😊"
    ":(": "😔"
}

output = ""
for word in words:
    output += emojis.get(word,word) + ' '

print(output)

这是语法错误。我不明白为什么冒号不正确。

line 6
    ":(": "😔"
        ^
SyntaxError: invalid syntax
python dictionary syntax
1个回答
1
投票

您需要添加逗号来分隔字典元素:

emojis = {
    ":)": "😊", # <- added comma here
    ":(": "😔"
}
© www.soinside.com 2019 - 2024. All rights reserved.