[英]How can I insert a string into quotations while keeping the string input in Python?
Random = (random.choice(Usernames))
print (str (Random))
studio.invite_curator (Random)
Text input in quotations is needed to complete the last line, yet I have a string that I need in the quotations.需要在引号中输入文本来完成最后一行,但我在引号中有一个字符串需要。 Is there any way to keep the quotations and the string in a new string variable?
有没有办法将引号和字符串保存在新的字符串变量中?
This is just a piece of code from my project, but I know there are not any problems with the other parts I do not have shown.这只是我项目中的一段代码,但我知道我没有展示的其他部分没有任何问题。
I tried to use this script:我试图使用这个脚本:
Random2 = '"',Random,'"'
studio.invite_curator (Random2)
But outputted as an error, because the final line of what I showed above needs to be in quotations.但是输出为错误,因为我上面显示的最后一行需要用引号引起来。 I can not yet find a way to work around this.
我还找不到解决这个问题的方法。
Use string concatenation instead of commas.使用字符串连接而不是逗号。
Random2 = '"' + Random + '"'
This will create a new string variable Random2 which contains the value of Random enclosed in quotation marks.这将创建一个新的字符串变量 Random2,其中包含用引号引起来的 Random 值。 Alternatively you could use f-strings to insert the variable into the string.
或者,您可以使用 f-strings 将变量插入到字符串中。
Random2 = f'"{Random}"'
studio.invite_curator(Random2)
This will also create a new string variable Random2 which contains the value of Random enclosed in quotation marks.这还将创建一个新的字符串变量 Random2,其中包含用引号引起来的 Random 值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.