Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use abstract classes in Python

1 Answer

0 votes
from abc import ABC, abstractmethod


class AbstractClass(ABC):

    def __init__(self, value):
        self.value = value

    @abstractmethod
    def method(self):
        pass


class Add(AbstractClass):
    def method(self):
        return self.value + 1


class Mul(AbstractClass):
    def method(self):
        return self.value * 2


a = Add(13)
m = Mul(8)

print(a.method())
print(m.method())


'''
run:
 
14
16
 
'''

 



answered Feb 13, 2018 by avibootz

Related questions

1 answer 138 views
1 answer 154 views
1 answer 151 views
1 answer 165 views
1 answer 137 views
137 views asked Apr 1, 2018 by avibootz
2 answers 313 views
313 views asked Jul 4, 2017 by avibootz
...