Python random

Asked 2 years ago, Updated 2 years ago, 18 views

def one():
    while True:
        print()
        if():

def two():
      while True:
        print()
        if():

If it's like this, I wonder how to make the entire def one() and def two() randomly output both!!

python

2022-09-20 21:56

1 Answers

The function can be executed randomly, as shown below.

def one():
    print('1')


def two():
    print('2')

import random

func_list = [one, two]
random.choice(func_list)()


2022-09-20 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.