0
Can functions be used as dictionaries value
I am planning a python project on Mad Libs and i wondered if functions can be used as dict value. e.g dict{ market : example() coding_experience : code() } print(dict[market])
2 Respostas
+ 3
Well, why not just try it?
https://code.sololearn.com/c610xc7TihC0/?ref=app
But I don't understand yet why you want to do it like that. Would a custom class or own module script or something do it?
+ 2
if you use dict constructor:
func = dict(market=example, coding_experience=code)
if you use dict literal:
func = {
"market": example,
"coding_experience": code,
}
in neither case you use parenthesis after function name (else you assign the function call return value instead of the function itself ^^)