Title: Choose a random function
Tags: python;python-3.x
Question: Using python 3.5 is it possible to have a list of definitions and have a function choose and call that random definition? I am asking this because all of the docs I have seen for random just says about generating a random pseudo number.

Comment: something that can be called from within that file/class e.g.
e.g. `def intro():
print("hello")
intro()`
Obviously with proper indentations and what not

Comment: Re: "… all of the docs I have seen for random just says about generating a random pseudo number" — The `random` module is included in the standard library and one can read its [fine documentation](https://docs.python.org/3/library/random.html#module-random). There I see the [description of the `choice` function](https://docs.python.org/3/library/random.html#random.choice): "_`random.choice(seq)` — — Return a random element from the non-empty sequence `seq`. If `seq` is empty, raises `IndexError`._".

Comment: [random.choice(seq)](https://docs.python.org/3/library/random.html#random.choice)

Comment: What is a definition?

Comment: So you mean a function? Functions are first-class objects in Python. You can put in them in any container and choose randomly from there.

Comment: add code in question, not in comment.

Comment: @M213081  `seq` can be list with function names

Comment: @M213081: Please edit your question, and include all the essential pieces of information. We have absolutely no idea what you are thinking unless you explain it well..

Here is the accepted answer: ```&gt;&gt;&gt; def foo(): print('foo')
&gt;&gt;&gt; def bar(): print('bar')
&gt;&gt;&gt; from random import choice
&gt;&gt;&gt; choice([foo, bar])
<function foo at 0x10499d668&gt;
&gt;&gt;&gt; choice([foo, bar])()
foo
&gt;&gt;&gt; choice([foo, bar])()
bar
&gt;&gt;&gt; choice([foo, bar])()
foo
```

Comment for this answer: Thank you. This is exactly what I was looking for.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 8, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:11/17/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><python-3.x>', 'Title': 'Choose a random function', 'ViewCount': 658, 'id': 40649777, 'user_AboutMe': '<p>A noob UK High school student who just needs a little nudge into the right direction sometimes.</p>\n', 'user_AccountId': 9563697.0, 'user_DisplayName': 'M213081', 'user_Reputation': 55.0, 'user_Views': 17.0, 'user_id': 7103622.0}}