如何在 python 的文本字符串中同时包含引号和双引号?

青葱年少 python 346

原文标题How can I include both quotes and double quotes in a text string in python?

我正在尝试自动化一个包含引号 ” 和 ‘ 的 Minecraft 命令。当我连接字符串变量时,它们会使开始和结束字符串的引号弄得一团糟。有没有办法避免这种情况?

Name = input("User name: ")
Age = input("User age: ")
Sex = input("User gender: ")
Job = input("User job: ")
Final = '/give @s flower_banner_pattern{display:{Lore:['{"text":"Name: " + Name + ","color":"white"}','{"text":"Age: " + Age + ','color":"white"}','{"text":"Sex: " + Sex + ","color":"white"}','{"text":"Job: " + Job + ','color":"white"}']}}'

你有什么想法?谢谢您的帮助!

[对不起我的英语我是意大利人]

原文链接:https://stackoverflow.com//questions/71456347/how-can-i-include-both-quotes-and-double-quotes-in-a-text-string-in-python

回复

我来回复
  • nicocid的头像
    nicocid 评论

    要在 python 中指示引号和双引号,您必须以下列方式指示它们:

    '-> Single quote for python string
    
    " -> Two quotes for python String
    

    我刚才指出的只是将那些字符放在字符串中,它们与字符串开头和结尾的引号无关

    2年前 0条评论