[英]switching between different quotation marks for output
我如何獲取代碼以更改輸出的引號。 我看到了一些提到json的參考,但我認為我需要自己編寫。 所以我將發布問題,然后發布我的代碼:
程序:quote_me()函數
quote_me接受字符串參數,並返回一個字符串,如果顯示該字符串,該字符串將顯示並帶有添加的雙引號
檢查傳遞的字符串是否以雙引號(“ \\”“)開頭,如果傳遞的字符串以單引號開頭,則檢查字符串是否為單引號;如果傳遞的字符串不是以引號開頭,則檢查字符串為雙引號
測試將字符串輸入作為quote_me()的參數的函數代碼
def quote_me(字):
if word == ("\'"):
str(word).replace ("\'", '\"')
else:
return word
打印(quote_me(input(“句子是什么:”)))
也許我也誤解了要求,如果是這樣,請告訴我。
def quote_me(word):
if word.startswith("\"") and word.endswith("\""):
word = word.replace("\"","\'")
elif word.startswith("\'") and word.endswith("\'"):
word = word.replace("\'","\"")
else:
word = "\""+word+"\""
return word
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.