简体   繁体   English

在python中用单引号初始化一个元组

[英]Init a tuple with single quote in python

how can I declare a tuple containing a quote in each side like this : (',')我怎样才能像这样声明一个包含引号的tuple :( (',')

I tried syntax = [("'","'")] but the output is incorrect我试过syntax = [("'","'")]但输出不正确

syntax[0][0]
Out[68]: "'"

I want the output to be just '我希望输出只是'

Use print function to see this.使用print功能可以看到这一点。

syntax = [("'","'")]
print(syntax[0][0]) # '

For me为了我

syntax = [("'","'")]
print(syntax[0][0])

prints out just '打印出来只是'

if you just print out syntax[0] you will get ("'", "'") but thats the only way it will work as you cant just have ' as that is not valid it has to be a string there fore in the tuple its represented in the double quotes如果你只是打印出语法 [0] 你会得到 ("'", "'") 但这是它工作的唯一方法,因为你不能只拥有 ' 因为它是无效的它必须是一个字符串元组它用双引号表示

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

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