In JS I can define an Object like this:
foo = {"foo": 42, "bar": function(){/* do something */}}
Is there a way to do the same thing in Python ?
The following might work:
# Define a function
def foo():
print("foo")
# Define a dictionary
d = {"a":1, "b":foo}
d["b"]()
Output: foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With