Skip to content

Instantly share code, notes, and snippets.

View rdcoder33's full-sized avatar

Raj Dhakad rdcoder33

View GitHub Profile
@rdcoder33
rdcoder33 / objects.py
Created December 26, 2018 02:52
By Raj Dhakad(RD)
class Person:
def __init__(self, first, last):
self.firstname = first
self.lastname = last
def name(self):
return f'{self.firstname} {self.lastname}'
class Person:
def __init__(self, first, last):
self.firstname = first
self.lastname = last
def name(self):
return f'{self.firstname} {self.lastname}'
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
def speak(self):
return 'blah blah'
class Dog(Animal):
class Robot:
def __init__(self, name, model_no, creator):
self.name = name
self.model_no = model_no
self.creator = creator
def walk(self):
return 'I am walking using my wheels'
class Superclass:
def class_names(self):
return 'I am super class'
class ClassA(Superclass):
def class_names(self):
return 'I am class A'
class Superclass:
super_class_call = 0
def class_call(self):
self.super_class_call += 1
print('I am Superclass')
class ClassA(Superclass):
class Superclass:
super_class_call = 0
def class_call(self):
print('I am Superclass')
self.super_class_call += 1
class ClassA(Superclass):
class Rectangle:
sides = 4
all_sides_equal = False
opposite_sides_equal = True
type = 'rectangle'
def area(self):
length = int(input('Enter length: '))
width = int(input('Enter width: '))
return length * width
@rdcoder33
rdcoder33 / composition.py
Last active December 27, 2018 04:37
Example of Composition
class Book:
def __init__(self, name, author, publisher):
self.name = name
self.author = author
self.publisher = publisher
def book_details(self):
return f'{self.name} by {self.author} from {self.publisher}'
class Book:
def __init__(self, name, author, publisher):
self.name = name
self.author = author
self.publisher = publisher
def book_details(self):
return f'{self.name} by {self.author} from {self.publisher}'