count newlines in string pythob code example Example: count a newline in string python length = x.count('\n')