0

look at the following code, I would like to know why the my_func doesn't return the "5". I know that if I remove the else statement It will work, but I would like to know what is happening, any doc or post that explain it?

def my_func(value):
    if value == 5:
        return 5
    else:
        yield from range(value)
        
print(my_func(5))
  • 1
    Duplicate of [Best way to receive the 'return' value from a python generator](https://stackoverflow.com/questions/34073370/best-way-to-receive-the-return-value-from-a-python-generator) – Samathingamajig Apr 25 '22 at 23:36
  • Check out this question as well: https://stackoverflow.com/questions/26595895/return-and-yield-in-the-same-function – D.Manasreh Apr 25 '22 at 23:39

0 Answers0