A
A
avion2018-04-01 22:59:09
Python
avion, 2018-04-01 22:59:09

FOR counter in Python?

Why does it output 0?

def print_nums(x):
    for i in range(x):
        print(i)
        return


print_nums(10)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavlo Ponomarenko, 2018-04-01
@avion123678

rangereturns numbers from 0 to 9 (inclusive). You output the first number and immediately end the function with a call to return. Try to remove return.

D
Dimonchik, 2018-04-01
@dimonchik2013

a pie on an empty stomach
and
returning a value by a function is
possible only ONCE
(but you can return many values ​​​​at a time if cho)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question