简体   繁体   English

在不同引号之间切换以输出

[英]switching between different quotation marks for output

how can i get my code to change the quotation marks of my output. 我如何获取代码以更改输出的引号。 i saw some references that mentioned json, but i think i need to write it myself. 我看到了一些提到json的参考,但我认为我需要自己编写。 so i'll post the question and then my code: 所以我将发布问题,然后发布我的代码:

Program: quote_me() Function 程序:quote_me()函数

quote_me takes a string argument and returns a string that will display surrounded with added double quotes if printed quote_me接受字符串参数,并返回一个字符串,如果显示该字符串,该字符串将显示并带有添加的双引号

check if passed string starts with a double quote ("\\""), then surround string with single quotations if the passed string starts with single quote, or if doesn't start with a quotation mark, then surround with double quotations 检查传递的字符串是否以双引号(“ \\”“)开头,如果传递的字符串以单引号开头,则检查字符串是否为单引号;如果传递的字符串不是以引号开头,则检查字符串为双引号

Test the function code passing string input as the argument to quote_me() 测试将字符串输入作为quote_me()的参数的函数代码

[ ] create and test quote_me() []创建并测试quote_me()

def quote_me (word): def quote_me(字):

if word == ("\'"):

    str(word).replace ("\'", '\"')

else:
    return word

print (quote_me(input ("what is the sentence: "))) 打印(quote_me(input(“句子是什么:”)))

maybe i've misunderstood what is required as well, if that's the case, please do tell. 也许我也误解了要求,如果是这样,请告诉我。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM