Can one function have multiple names?

前端 未结 3 1181
离开以前
离开以前 2021-01-21 01:53

I\'m developing a bot on Python (2.7, 3.4). I defined a about 30+ dynamic functions which to be used based on bot commands. While development, since not all functions are done,

3条回答
  •  抹茶落季
    2021-01-21 02:46

    Yes, it is possible, and it is even possible to store them in lists using loops. For instance:

    l = []
    for i in range(10):
        l.append(lambda: None)
    

    And you can reference any of them through indices like l[index]()

    For example:

    c_events = 0
    c_about = 1
    l[c_events]()
    

提交回复
热议问题