代码是这个:
print('C:\users\desktop')
出现这个报错:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
“\”在python中表示转义,而”\”打算将u转义为有意义的符号,而”\”并未能如愿,因为没有对应的转义字符。这时只能报上述的错误SyntaxError: (unicode error) ‘unicodeescape’ 。应该改为“/”
即应改为:
print('C:/users/desktop')
也可以改为:
print(r'C:\users\desktop')
在字符串前加个 r 是为了告诉编译器这个string是个raw string,不要转义。