SyntaxError when trying to use backslash for Windows file path
问题 I tried to confirm if a file exists using the following line of code: os.path.isfile() But I noticed if back slash is used by copy&paste from Windows OS: os.path.isfile("C:\Users\xxx\Desktop\xxx") I got a syntax error: (unicode error) etc etc etc. When forward slash is used: os.path.isfile("C:/Users/xxx/Desktop/xxx") It worked. Can I please ask why this happened? Even the answer is as simple as :"It is a convention." 回答1: Backslash is the escape symbol. This should work: os.path.isfile("C:\