-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcall_usage.py
More file actions
47 lines (35 loc) · 789 Bytes
/
call_usage.py
File metadata and controls
47 lines (35 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
# Date: 2018-10-16
#
# Description:
# __call__() method makes an object of a class and class name as callable.
class A:
g_data = []
def __init__(self, data):
self.g_data.append(data)
def __call__(self):
for d in self.g_data:
print (d)
a1 = A('Nisha')
a2 = A('Mahabeer')
a3 = A('Khargosh')
print ('*********A(Test)**********')
A('Test') # This only calls __init__() not __call__()
print ('*********a3()**********')
a3() # Calls __call__() method
print ('*********A(Test1)()**********')
A('Test1')() # Creates object and calls __call__()
# Output:
# ------------------
# *********A(Test)**********
# *********a3()**********
# Nisha
# Mahabeer
# Khargosh
# Test
# *********A(Test1)()**********
# Nisha
# Mahabeer
# Khargosh
# Test
# Test1