我正在嘗試自動化一個包含引號“和”的 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"}']}}'
你有什么想法?謝謝您的幫助!
[對不起我的英語我是意大利人]
uj5u.com熱心網友回復:
要在 python 中指示引號和雙引號,您必須以下列方式指示它們:
\'-> Single quote for python string
\" -> Two quotes for python String
我剛才指出的只是將那些字符放在字串中,它們與字串開頭和結尾的引號無關
uj5u.com熱心網友回復:
有時同時使用'and是錯誤的。"如果你打算同時使用單雙引號和多引號,我建議你用\主引號和主引號分開。以下示例將使您深入了解該指令:
myString = 'there is a few quotations such as this \' and this \'. There is no need to use slash with ".'
print(myString)
輸出
there is a few quotations such as this ' and this '. There is no need to use slash with ".
uj5u.com熱心網友回復:
我不知道 Minecraft 命令是如何作業的,但是如果你用單引號開始 Final 變數',那么如果你想在字串中間使用單引號,你應該這樣做\'。
這意味著以下應該起作用:
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://www.uj5u.com/gongcheng/442520.html
上一篇:如何使其三元化?
