mardi 25 octobre 2022

Python List of Functions without Executing

I'm working on a Python project, and part of it is where it chooses a function from random via list. Unfortunately, when it's declaring the list, its executing the function. Is there a way to have a list of functions without them executing?

Here's example code:

import random
def a():
  global var
  var = 1
def b():
  global var
  var = 2
list = [a(), b()]
print(var)

Outcome:

>>> 2



Aucun commentaire:

Enregistrer un commentaire