繁体   English   中英

使用单引号或双引号以外的其他内容来设置变量?

[英]Using something other than single or double quotes to set variable?

我有一些包含许多单引号和双引号的硬编码文本。

text = "get in the "van" I said get in the 'van'"

我可以使用\\对每个双引号进行转义,也可以在外部切换为单引号并对每个单引号进行转义。

我想做的就是能够选择其他东西,例如! 我能做些简单的事情吗? 在Perl中,我始终能够:

text = qq!this will use "whatever" I'm happy with!

如果有帮助,我正在使用Python 3.6。

初始化字符串的另一个选项是使用"""'''

text = """get in the "van" I said get in the 'van'"""

您还可以串联多个字符串

text = 'get in the "van" I said get in the ' "'van'"

暂无
暂无

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

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