For example, I get a string:
str = \"please answer my question\"
I want to write it to a file.
But I need to know the size of the s
The most Pythonic way is to use the len()
. Keep in mind that the '\' character in escape sequences is not counted and can be dangerous if not used correctly.
>>> len('foo')
3
>>> len('\foo')
3
>>> len('\xoo')
File "", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \xXX escape