For example,
Assuming that the functions draw_nose
and draw_eye
are defined
drawing = { 'nose' : draw_nose, 'eye' : draw_eye}
Define a drawing dictionary and
If I enter the key value of the dictionary, can't the function of the value be executed?
python dictionary function
why not
>>> def dog barking (): print ("Boo-boo-boo~~")
>>> def Cat barks (): print ("Meow Meow Meow meow~)~~")
>>> Animal = { "Dog": Dog barking, "Cat": Cat barking}
>>> Animal ["Dog"]
<function dog barking at 0x0000018B03474D90>
>>> Animal ["Dog"]()
Woof woof woof!
>>> Animal ["Cat"]()
Meow, meow~
© 2024 OneMinuteCode. All rights reserved.