This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Chocolate: | |
| def __init__(self): | |
| self.__maxprice = 290 | |
| def sell(self): | |
| print("Selling Price:{}".format(self.__maxprice)) | |
| def setMaxPrice(self, price): | |
| self.__maxprice = price |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Sparrow: | |
| def flight(self): | |
| print("Sparrow can fly") | |
| def swim(self): | |
| print("Sparrow can't swim") | |
| class Penguin: | |
| def flight(self): | |
| print("Penguin can't fly") | |
| def swim(self): | |
| print("Penguin can swim") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class B: | |
| class A: | |
| def a1(self): | |
| print("a1") | |
| class B(A): | |
| def b(self): | |
| print("b") | |
| b = B() | |
| b.a1() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Adder: | |
| def __init__(self): | |
| self.sum = 0 | |
| def add(self,value): | |
| self.sum += value | |
| acc = Adder() | |
| for i in range(99): | |
| acc.add(i) | |
| print(acc.sum) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A(object): | |
| def a1(self): | |
| print("a1") | |
| class B(object): | |
| def b(self): | |
| print("b") | |
| A().a1() | |
| objectB =B() | |
| objectB.b() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| class Section(metaclass=ABCMeta): | |
| @abstractmethod | |
| def describe(self): | |
| pass | |
| class PersonalInfoSection(Section): | |
| def describe(self): | |
| print("Personal information section") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| class Employee(metaclass=ABCMeta): | |
| @abstractmethod | |
| def create(self): | |
| pass | |
| class manager(Person): | |
| def create(self, name): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| class PizzaFactory(metaclass=ABCMeta): | |
| @abstractmethod | |
| def createVegPizza(self): | |
| pass | |
| @abstractmethod | |
| def createNonVegPizza(self): | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Singleton(object): | |
| def __new__(cls): | |
| if not hasattr(cls, 'instance'): | |
| cls.instance = super(Singleton,cls).__new__(cls) | |
| return cls.instance | |
| s = Singleton() | |
| print("Object created",s) | |
| sA = Singleton() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Singleton: | |
| __instance = None | |
| def __init__(self): | |
| if not Singleton.__instance: | |
| print("__init__ method is called.") | |
| else: | |
| print("Instance is already created :",self.getInstance()) | |
| @classmethod | |
| def getInstance(cls): |
OlderNewer