Created On: August 26, 2021, Last Updated On: August 26, 2021

Python Classes function defination

Public

By Ozzie Ghani3 new







import random
import inspect


class TEST:

    def __init__(self, num):
        self.num = num


    def info(self, f=None):
        print("\nINFO ========")
        print("class: " + self.__class__.__name__)
        print("function: " + f.__name__)

        if f is None:
            return {"num": self.num}
        else:
            return inspect.getdoc(f)


    def number(self):
        """
        :param f: which function to run
        :return:
        """

        return self.num


if __name__ == '__main__':
    r = TEST(num=4)
    print(r.info(f=r.number))







INFO ========
class: TEST
function: number
:param f: which function to run
:return:

Output