lundi 28 juin 2021

Can I create a List of functions in python?

I am trying to create a list of functions in my program in order to use the random module to randomly choose. in theory it look and work with this

import random

def test1():
  print("1st function")

def test2():
  print("2nd function")

def test3():
  print("3rd function")

def test_func():
  test_list = [test1(), test2(), test3()]
  apple = random.choice(test_list)
  return print(apple)

test_func()

the result of this is it prints out test_list and prints "NONE" for apple is there a way to get it to randomly pick a function and only print that function.




Aucun commentaire:

Enregistrer un commentaire