20
loading...
This website collects cookies to deliver better user experience
class Car:
#class attributes
Color="Red"
YOM = "2015"
Model = "Mazda"
pass
class Dog:
species = 'Canis lupus'
def __init__(self,color,weight,height):
self.color = color
self.weight = weight
self.height = height
class Car:
def __init__(self,color,YOM,model):
self.color = color
self.YOM = YOM
self.model = model
class Car:
def __init__(self,color,YOM,model):
self.color = color
self.YOM = YOM
self.model = model
Car1 = Car('white','2015','Toyota')
print ( f'This is a {Car1.color},{Car1.model},manufactured in {Car1.YOM}')
This is a white,Toyota,manufactured in 2015
Car1 = Car()
class Car:
def __init__(self,color,YOM,model):
self.color = color
self.YOM = YOM
self.model = model
#method
def hoot(self):
return('Pipippipi')
Car3 = Car('Blue','2018','Mazda')
Car3.hoot()
print(f'The {Car3.color},{Car3.YOM},{Car3.model} is hooting {Car3.hoot()}')
The white,2016,Mazda is hooting Pipippipi
#Parent Class
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
#method
def printname(self):
print(self.firstname, self.lastname)
#child class
class Student(Person):
def __init__(self, fname, lname):
Person.__init__(self, fname, lname)
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
#method
def printname(self):
print(self.firstname, self.lastname)
class Student(Person):
def __init__(self, fname, lname):
super().__init__(fname, lname)
self.graduationyear = 2019
class whale:
def swim(self):
print("The whale is swimming.")
def swim_backwards(self):
print("The whale cannot swim backwards, but can sink backwards.")
def skeleton(self):
print("The whale's skeleton is made of cartilage.")
class Starfish():
def swim(self):
print("The Starfish is swimming.")
def swim_backwards(self):
print("The Starfish can swim backwards.")
def skeleton(self):
print("The Starfish's skeleton is made of bone.")
waza = whale()
herod = Starfish()
for fish in (waza, herod):
fish.swim()
fish.swim_backwards()
fish.skeleton()
The whale is swimming.
The whale cannot swim backwards, but can sink backwards.
The whale's skeleton is made of cartilage.
The Starfish is swimming.
The Starfish can swim backwards.
The Starfish's skeleton is made of bone.
from django import models
class student(models.Model)
pass