forked from edyoda/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py
98 lines (44 loc) · 1 KB
/
classes.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class ClassName:
'Optional description'
var1 = 0
def __init__(self, name, id):
self.name = name
self.id= id
def method1(self):
print 'this is method 1'
obj1 = ClassName("ABC", 2)
obj1.method1()
print ClassName.var1
obj1.age = 4
obj1.address= 'street'
del obj1.age
del ClassName.var1
print (hasattr(obj1, 'age'))
print getattr(obj1, 'address')
setattr(obj1, 'age', 'xyz')
delattr(obj1, 'age')
print (hasattr(obj1, 'age'))
print ClassName.__doc__
print ClassName.__name__
print ClassName.__bases__
print ClassName.__dict__
print ClassName.__module__
class ChildClass (ClassName):
'Inheriting class ClassName'
var2 = 5
__secretNum = 6
def __init__(self):
print ' this is child class constructor'
def method2(self, name):
print name
def method1(self):
print 'this is child class method1'
c = ChildClass()
c.method2("XYZ")
c.method1()
print c._ChildClass__secretNum
class Vehicle :
def calcSpeed(self) :
print 'hi'
c= Vehicle()
c.calcSpeed()