T
T
toshk92020-08-20 00:11:26
Python
toshk9, 2020-08-20 00:11:26

Is there a library or built-in method in Python that counts the number of lines(\n) in a string(" ")?

It is necessary to iterate not over the individual elements of the line, but over its lines, no matter how strange it may sound. Is there any method that would count the strings in the string "".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery Mamontov, 2020-08-20
@toshk9

toshk9 , this is also possible:

>>> a = """ добрый день
... сейчас я на работе
... освобожусь позже
... и перезвоню
... """
>>> c = a.count("\n")
>>> c
4
>>>

D
Dimonchik, 2020-08-20
@dimonchik2013

yes: len
he counts a lot more

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question