Can functions be used as dictionaries value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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])

20th Jun 2021, 7:36 PM
Haxsys
Haxsys - avatar
2 Answers
+ 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?
20th Jun 2021, 8:01 PM
Lisa
Lisa - avatar
+ 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 ^^)
20th Jun 2021, 8:53 PM
visph
visph - avatar