What is the output of the following code ?
class Foo:
data = 'welcome'
def __init__(self, value):
self.data = value
def printme(self):
print(self.data, Foo.data)
p = Foo('python')
e = Foo('easy')
p.printme()
e.printme()
What is the output of the following code ?
class Foo:
data = 'python'
def set_data(self, value):
self.data = value
def printme(self):
print(self.data, Foo.data)
p = Foo()
p.printme()
p.set_data('easy')
p.printme()
What is the output of the following code ?
class Foo:
def printme(self, data):
print(data)
p = Foo()
p.printme('hello')
Foo.printme(p, 'hello')
What is the output of the following code ?
class TestAttr:
def __init__(self):
self.X = 'Pre'
self.value_change(self.X)
def value_change(self, var):
var = 'Post'
obj = TestAttr()
print(obj.X)
What is the output of the following code ?
class MyClass:
def __init__(self, cost):
self.cost = cost
obj = MyClass(70)
obj.count = 20
obj.containers = 5
print(obj.count + len(obj.__dict__))
What is the output of the following code ?
class MyClass:
def __init__(self, cost):
self.cost = cost
def print_name(self):
print(__name__, MyClass.__name__)
obj = MyClass(70)
obj.print_name()
What does the following code print in the interpreter ?
>>> class Sample():
... def __repr__(self):
... return '__repr__ is called'
... def __str__(self):
... return '__str__ is called'
...
>>> p = Sample()
>>> p
What does the following code print in the interpreter ?
>>> class Sample():
... def __repr__(self):
... return '__repr__ is called'
... def __str__(self):
... return '__str__ is called'
...
>>> p = Sample()
>>> print(p)
Which special method overloads + operator ?
Which operator is overloaded by __invert__() special method?