0
def Test_1():
    x = 1
    for i in range(0,6):
        y = "Road" + str(x) + "()"
        y
        x = x + 1
        print("end")

What would be the correct way to call Function: Road1() - Road6() ? Like this :

def Test_1():
    Road1()
    Road2()
    Road3()
    Road4()
    ...
    Road6()
    print("end")
  • I'm not sure what exactly is being asked here, but this seems to be related to [this](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables). If you're trying to dynamically create variables/functions though, using a dictionary or list would be much better. – Carcigenicate May 05 '20 at 23:52
  • what you want is `eval`. [see here](https://stackoverflow.com/questions/9383740/what-does-pythons-eval-do) – impopularGuy May 06 '20 at 02:46

1 Answers1

0
def Test_1():
    for x in range(1,7):
        y = "Road" + str(x) + "()"
        eval(y)
    print("end")

EDIT Aug 2022: Using eval is not a good idea. In Python we can call functions using its name string as shown here

impopularGuy
  • 805
  • 9
  • 15