How to check for a new line in a string?
Does python3.x have anything similar to java's regular operation where direct if (x=='*\n')
would have worked?
If you just want to check if a newline (\n
) is present, you can just use Python's in
operator to check if it's in a string:
>>> "\n" in "hello\ngoodbye"
True
... or as part of an if
statement:
if "\n" in foo:
print "There's a newline in variable foo"
You don't need to use regular expressions in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With