variable-variables

How can I select a variable by (string) name?

How can I select a variable by (string) name? Question: I want to return a pre-determined list from my function, based on the string input. def get_ext(file_type): text = [‘txt’, ‘doc’] audio = [‘mp3’, ‘wav’] video = [‘mp4’, ‘mkv’] return # what do I return here? get_ext(‘audio’) #should return the list [‘mp3’, ‘wav’] What is …

Total answers: 5

How do I create variable variables?

How do I create variable variables? Question: I know that some other languages, such as PHP, support a concept of "variable variable names" – that is, the contents of a string can be used as part of a variable name. I heard that this is a bad idea in general, but I think it would …

Total answers: 17