Answers for "python list class definition"

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
19

python class

class Person:#set name of class to call it 
  def __init__(self, name, age):#func set ver
    self.name = name#set name
    self.age = age#set age
   

    def myfunc(self):#func inside of class 
      print("Hello my name is " + self.name)# code that the func dose

p1 = Person("barry", 50)# setting a ver fo rthe class 
p1.myfunc() #call the func and whitch ver you want it to be with
Posted by: Guest on June-12-2020
0

list class in python

class MyClass:
    def __init__(self, signature):
        self.signature = signature

    def __repr__(self) -> str:
        return str(self.signature)

class_list = []

for i in range(10):

    class_list.append(MyClass(i))

print (class_list) # outputs [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Posted by: Guest on June-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language