Split a string by backslash in python

后端 未结 5 1198
悲哀的现实
悲哀的现实 2020-12-06 09:41

Simple question but I\'m struggling with it for too much time. Basically I want to split a string by \\ (backslash).

 a = \"1\\2\\3\\4\"

Tr

5条回答
  •  春和景丽
    2020-12-06 10:10

    You can split a string by backslash using a.split('\\').

    The reason this is not working in your case is that \x in your assignment a = "1\2\3\4" is interpreted as an octal number. If you prefix the string with r, you will get the intended result.

提交回复
热议问题