how to get the number of lines in a string python code example Example: count a newline in string python length = x.count('\n')