Answers for "what is a class python"

16

declare class python

# To create a simple class:
class Shape:
  	def __init__():
      	print("A new shape has been created!")
      	pass
    
    def get_area(self):
		pass

# To create a class that uses inheritance and polymorphism
# from another class:
class Rectangle(Shape):
  
	def __init__(self, height, width): # The constructor
    	super.__init__()
        self.height = height
    	self.width = width

	def get_area(self):
      	return self.height * self.width
Posted by: Guest on March-08-2020
0

class python example

# If questions ask SK3#3160 he can help you i think
def ok(index):
    print(index) > Hi!
ok("Hi!")
class Lib:
    def ok(self,Token):
        print(Token) > Hello World!
Library = Lib()
Library.ok("Hello World!")
Posted by: Guest on January-08-2021
0

class python

class A:        # define your class A
.....

class B:         # define your class B
.....

class C(A, B):   # subclass of A and B
  
obj = C() #to create instance
# issubclass(sub, sup) boolean function returns true if the given 
# subclass sub is indeed a subclass of the superclass sup

# isinstance(obj, Class) boolean function returns true if obj is an 
# instance of class Class or is an instance of a subclass of Class
Posted by: Guest on November-24-2020
-1

class python

class Charge:
    def __init__(self, employee, discount):
        self.employee = employee
        self.discount = discount
        
    def _discounted_pricey(self):
        item_price = 100
        discounted_price = item_price * (1-self.discount)
        return discounted_price
        
    def __discounted_price(self):
        item_price = 100
        discounted_price = item_price * (1-self.discount)
        return discounted_price

    def pays(self):
        price_to_charge = self.__discounted_price() # gotcha: self.
        print(f'Charge {self.employee} ${price_to_charge:.2f} ({self.discount:.2%} off)')
    
Employee = Charge(employee='Billy Beans', discount=.1)

print(Employee.employee) # Billy Beans
print(Employee.discount) # 0.1
print(Employee._discounted_pricey()) # 90.0
print(Employee.__discounted_price()) # AttributeError: 'Charge' object has no attribute '__discounted_price'
print(Employee.item_price) # AttributeError: 'Charge' object has no attribute 'item_price'
Employee.pays() # Charge Billy Beans $90.00 (10.00% off)
Posted by: Guest on August-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language