Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么打印的是@而不是\100?_Python_Variables_Printing_While Loop - Fatal编程技术网

Python 为什么打印的是@而不是\100?

Python 为什么打印的是@而不是\100?,python,variables,printing,while-loop,Python,Variables,Printing,While Loop,我有以下计划: x = 0 while x <= 10: print(x, '\10') x = x + 1 而不是: 1\10,2\10等等 程序为什么要这样做?您正在用\符号转义10,而python将\10解释为@符号的代码。您可以通过将r字符作为字符串的前缀或用另一个字符转义反斜杠来解决此问题 Fix: r'\10' #Raw string Or: '\\10' 因为'\100'是'@',那么如何打印\100?打印(\\100”)。仔细阅读逃生和特殊

我有以下计划:

x = 0

while x <= 10:
   print(x, '\10')
   x = x + 1
而不是:

1\10
2\10
等等


程序为什么要这样做?

您正在用
\
符号转义10,而python将
\10
解释为
@
符号的代码。您可以通过将
r
字符作为字符串的前缀或用另一个字符转义反斜杠来解决此问题

Fix:
    r'\10' #Raw string
Or:
    '\\10'

因为
'\100'
'@'
,那么如何打印
\100
打印(\\100”)
。仔细阅读逃生和特殊角色。@RulerOfTheWorld:为什么不呢?
Fix:
    r'\10' #Raw string
Or:
    '\\10'