简体   繁体   English

是否有可能在输入 class 中产生错误,或者 str 和输入有什么区别?

[英]Is it possible to create an error in the input class, or what is the difference between str and input?

If I try to place the following value: "' as text when by putting it in brackets as follows: a = str(""'") , it will give the following error:如果我尝试将以下值: "'作为文本放在括号中,如下所示: a = str(""'") ,它将给出以下错误:

SyntaxError: EOL while scanning string literal

On the other hand if I enter "' as an input it will accept it by default as a string.另一方面,如果我输入"'作为输入,它将默认接受它作为字符串。

How does the input class manage to convert it to string?输入 class 如何将其转换为字符串?

And is there any sequence of keys that will cause the input class to get an error when receiving a value and converts it to string?是否有任何键序列会导致输入 class 在接收值并将其转换为字符串时出错?

When you want both quote marks: " and ' inside a literal string, you can either add them separately or you can use so-called triple-quotes to surround them:当你想要两个引号: "'在一个文字字符串中时,你可以单独添加它们,也可以使用所谓的三引号将它们括起来:

a = '''""' '''  # note the trailing space
b = """ ""'"""  # note the leading space
print(a)
print(b)

This may not be what you want.这可能不是你想要的。

Alternatively:或者:

double = '"'
single = "'"
a = double + single
print(a)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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