class A:
def __init__(self):
self.__x = 1
def get_x(self):
return self.__x
class B(A):
def __init__(self):
super().__init__()
self.__x = 2
b = B()
print(b.get_x())
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
def increment(x):
x += 10
return x
value = 5
new_value = increment(value)
print(value + new_value)
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
data = [5, 10, 15, 20]
data.extend([x // 2 for x in data[:2]])
print(sum(data))
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
class MetaClass(type):
def __new__(cls, name, bases, dct):
dct['meta_value'] = 100
return super().__new__(cls, name, bases, dct)
def __init__(cls, name, bases, dct):
cls.meta_value += len(name)
class A(metaclass=MetaClass):
pass
class B(metaclass=MetaClass):
pass
print(A.meta_value + B.meta_value)
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM