In this specific case, no query are executed at all. It is only str objects which means that they actually don't do anything.
Let's try to detail 2 other cases. Assuming you have a function execute_query that execute a query given as parameter:
def func(query):
my_dict = {
'query1': execute_query('select * from table1'),
'query2': execute_query('select * from table2'),
}
return my_dict[query]
func('query1')
In this case, both query will be executed because Python interpreter will analyse the dictionary composition. On the other hand, if you have a reference to this function, it won't call the function. Example:
def do_query1():
return execute_query('select * from table1')
def do_query2():
return execute_query('select * from table2')
def func(query):
my_dict = {
'query1': do_query1,
'query2': do_query2,
}
return my_dict[query]() # <-- appropriate function will be call here
func('query1')
my_dictifbaris one of the keys of the same dictionary...