【问题标题】:Replacing some emoticons with emojis in python在python中用表情符号替换一些表情符号
【发布时间】:2022-07-23 23:59:38
【问题描述】:

这是我的代码目前的样子。当用户输入句子或单词时,我想将表情符号更改为表情符号。我该怎么走?

def main():
    sentence = input("Input a Sentence: ")
    convert(sentence)
    print(sentence)


def convert():
    emo1 = ":)"
    emo2 = ":("
    emo1.replace(":)", "????")
    emo2.replace(":(", "????")


main()

【问题讨论】:

  • 字符串是不可变的

标签: python replace emoji emoticons


【解决方案1】:

您需要在发送到function convert的句子中添加替换表情。

def main():
    sentence = input("Input a Sentence: ")
    print(sentence)
    sentence = convert(sentence)
    print(sentence)


def convert(sentence):
    sentence = sentence.replace(":)", "?")
    sentence = sentence.replace(":(", "?")
    return sentence


main()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-03
    • 2021-09-26
    • 2021-01-13
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 2014-03-27
    相关资源
    最近更新 更多