Create class in Python

    0

    71

    Python public recipes

    Generic create a class in Python

    This recipe creates a class in Python, taking the filename to name the class. It also declares and uses the __eq__ method to test object equality.

    Examples of use

    m = YourNewClass(1)
    n = YourNewClass(2)
    p = YourNewClass(1)
    
    print(m == p) # return true
    print(n == p) # return false
    
    class ClassName:
      """
      Generic Python class
      :param argument1: argument passed to the class and store as variable
      """
      def __init__(self, argument1):
        self.argument1 = argument1
      def __eq__(self, other):
        if isinstance(other, ClassName):
        	return self.argument1 == other.argument1
        return False
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.