- emoji converter(知识点:字典,映射)
message = input(">")#用户输入消息(先右边再写左边是个好习惯)
words=message.split(' ')#用空格将字符串分割(split里面的单引号或者双引号没多大影响)
print(words)
--执行--
>I love python so much
['I', 'love', 'python', 'so', 'much']
#将空格改为o
>I love you so much
['I l', 've y', 'u s', ' much']
message = input(">")#用户输入消息
words = message.split(' ')#用空格将字符串分割
emojis = {
":)":"😁",
":(":"😔"
}#字典
output = ""#定义一个输出变量
for word in words:
output += emojis.get(word,word)+" "#get函数:字典中的映射,而不是字典中的原样输出,为什么最后加个空格?
print(output)
--执行--&#