How to check newline in line in Python 3.x?

How to check a new line in a line?

Does python3.x have something similar to a regular java operation where the direct if (x=='*\n') ?

+7
source share
2 answers

If you just want to check if there is a new line ( \n ), you can simply use the Python in statement to check if it is in the line:

 >>> "\n" in "hello\ngoodbye" True 

... or as part of an if :

 if "\n" in foo: print "There a newline in variable foo" 

In this case, you do not need to use regular expressions.

+23
source

Yes, like this:

 if '\n' in mystring: ... 

(Python has regular expressions, but in this case they are too crowded.)

+9
source

All Articles