0
How to count len() without \n?
2 Answers
+ 5
Use str.strip() to remove whitespace from the string.
" test \n".strip()
results in "test"
+ 3
OR if there are "\n" in middle of string for example:
x = "Hello \n World"
(This can't be removed by strip)
So here, use string.replace() method:
x = x.replace("\n", "")
Parameters:
x.replace(old_char, new_char)
Then len(x)