Z
Z
Zac Rider2020-08-10 15:21:59
Python
Zac Rider, 2020-08-10 15:21:59

Why does the function output only the first line?

Help me understand the problem: why does my code output only the first line of the document?

Document text:

testing text, is this working???
yes
guess so
maybe yes or maybe not
maybe yes or maybe not


The code:
f = open('kittenB00ks.txt', 'r')


def bruhhhhhhh():
    for i in f:
        return i


print(bruhhhhhhh())

f.close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-08-10
@b00tyCha1n

Because the operator returnterminates the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question