Answers for "simple 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
3

class python

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p1 = Person("John", 36)

p1.age = 40

print(p1.age)
---------------------------------------------------------------
40
Posted by: Guest on October-29-2020
4

python class

class Dog(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def speak(self):
        print("Hi I'm ", self.name, 'and I am', self.age, 'Years Old')

JUB0T = Dog('JUB0T', 55)
Friend = Dog('Doge', 10)
JUB0T.speak()
Friend.speak()
Posted by: Guest on November-20-2020
2

classes in python

class Foo:
  def __init__(self):
    self.definition = Foo!
  def hi():
    # Some other code here :)
    
# Classes require an __init__ if you want to assign attributes. (self) defines what describes the attribs.
Posted by: Guest on January-21-2021
0

How to make a new class in python

#Use the class function and give the class a name
#next use the def __init__() to initilaize and give it some properties.
class Fruits():
  def __init__(self, name, colour, taste):
    self.name = name
    self.colour = colour
    self.taste = taste
#Now create an object by first calling the class
fruit1 = Fruits(apple, red, sweet)
print(fruit1.name)
#this will print the name which is apple
print(fruit1.colour)
#this will print the colour which is red
print(fruit1.taste)
#this will print the taste which is sweet
Posted by: Guest on November-01-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

Python Answers by Framework

Browse Popular Code Answers by Language