defining a class python code example

Example 1: class python

class MyClass(object):
  def __init__(self, x):
    self.x = x

Example 2: python class

class Animal(object): # Doesn't need params but put it there anyways.
    def __init__(self, species, price):
        self.species = species # Sets species name
        self.price = price # Sets price of it
    
    def overview(self): # A function that uses the params of the __init__ function
        print(f"This species is called a {self.species} and the price for it is {self.price}")

class Fish(Animal): # Inherits from Animal
    pass # Don't need to add anything because it's inherited everything from Animal
 
salmon = Fish("Salmon", "$20") # Make a object from class Fish
salmon.overview() # Run a function with it
dog = Animal("Golden retriever", "$400") # Make a object from class Animal
dog.overview() # Run a function with it

Example 3: class methods in python

@classmethod
def func(cls, args...)

Example 4: class in python

class LambdaClass: 
    x = lambda a, b, c, d, e, f: a + b + c + d + e + f
    print(x(31231, 312, 312, 31, 12, 31))

print(LambdaClass)