In javascript, I do can add a function parameter to my function class like so:
const MyFunc = function(){
const myfunc = this
myfunc.hi = () => {
console.log('hi')
}
}
const myFunc = new MyFunc()
myFunc.hi()
What is the equivalent in python?
class MyClass:
def __init__(self, hi):
self.hi = def func():
print('hi')
>Solution :
You could use a lambda.
self.hi = lambda: print('hi')
But it makes more sense to define a method on the class instead.
class MyClass:
def hi(self):
print('hi')
MyClass().hi()