python打不出单引号是什么原因
Python的单引号通常可以表示字符串。若字符串没有引号嵌套,则对可打印转义字符(,',",ooo,xhh)进行转义。若字符串有引号嵌
套,则对嵌套内部字符全部不进行转义,保持原始格式;对嵌套外部字符参照1进行转义。
注意print会对所有转义字符进行转义。
下面是几个例子:
>>> 'spam eggs' 'spam eggs' >>> 'doesn't' # 对可打印字符转义 "doesn't" >>> "doesn't" # 同上 "doesn't" >>> "doesn't" # 这样可以省去 "doesn't" >>> '"doesn't"' # 嵌套后内部全部不进行转义 '"doesn't"' >>> ""Yes," he said." # 同类型引号,需要进行转义 '"Yes," he said.'
来源:PY学习网:原文地址:https://www.py.cn/article.html