选择一个随机函数

选择一个随机函数

问题描述:

使用Python 3.5有可能有一个定义列表,并有一个功能选择和调用随机定义?我在问这是因为我随机看到的所有文档都只是说产生一个随机的伪数字。选择一个随机函数

+0

什么是高清? –

+0

可以从该文件/类中调用的内容 例如'DEF介绍(): 打印( “你好”) 介绍()'适当压痕,什么 显然不是 – M213081

+0

[random.choice(SEQ)(https://docs.python.org/3/library/ random.html#random.choice) – Lafexlos

>>> def foo(): print('foo') 
>>> def bar(): print('bar') 
>>> from random import choice 
>>> choice([foo, bar]) 
<function foo at 0x10499d668> 
>>> choice([foo, bar])() 
foo 
>>> choice([foo, bar])() 
bar 
>>> choice([foo, bar])() 
foo 
+0

谢谢。这正是我所期待的。 – M213081