How can I check for a new line in string in Python 3.x?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)