Just like the title said.
For example:
I have a class like this:
class NewClass():
def func1():
.....
then I want to add a new function into this class when program file running.
just like reassign a new value to the attribute of the class.
e.g.
NewClass.a = 3
If you want to add a function to the class type itself, you can just assign it, making sure to include the argument for the self-reference passed:
You can use
types.MethodType()to create a bound instance method if you only want to add the function to a single instance of the class: