How to deal with strings containing character codes?
Question:
201
is a character code recognised in Python. What is the best way to ignore this in strings?
s = '2016'
s = s.replace('\', '/')
print s #6
Answers:
If you have a string literal with a backslash in it, you can escape the backslash:
s = '\2016'
or you can use a “raw” string:
s = r'2016'
201
is a character code recognised in Python. What is the best way to ignore this in strings?
s = '2016'
s = s.replace('\', '/')
print s #6
If you have a string literal with a backslash in it, you can escape the backslash:
s = '\2016'
or you can use a “raw” string:
s = r'2016'