0

This is my nested functions code

   def get_id():
        for i in range(1,100):
            pass
            return i
    def get_id_mysql(x):
        print(x)
    
    
    variable = get_id()
    get_id_mysql(variable)

this function get_id return ( output : 1 ) and loop stop.. how can I hand over full loop? I mean 1,2,3..99

CaptainPy
  • 69
  • 1
  • 6

1 Answers1

0

I Found solutions

def get_id():
    t = []
    for i in range(1,100):
        t.append(i)
    return t
def get_id_mysql(x):
    for i in x:
        print(i)


variable = get_id()
get_id_mysql(variable)
CaptainPy
  • 69
  • 1
  • 6
  • 1
    In this example, `get_id` does not need to exist at all, just `get_id_mysql(range(1, 100))`. You can learn about [What are iterator, iterable, and iteration?](https://stackoverflow.com/questions/9884132/what-are-iterator-iterable-and-iteration) – Mechanic Pig Sep 08 '22 at 17:39
  • to add to what @MechanicPig said, you can also use list comprehension `[i for i in range(1, 100)]` – Daniel Afriyie Sep 08 '22 at 18:37