-
Notifications
You must be signed in to change notification settings - Fork 11
/
Example4.py
40 lines (26 loc) · 922 Bytes
/
Example4.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
#Call declaration program
''' Python3 program to show that the variables with a value assigned in the class declaration, are class variables and variables inside methods and constructors are instance
variables.'''
class Example4:
# Class Variable
name = 'Human'
# The init method or constructor
def __init__(self,age, color):
# Instance Variable
self.age = age
self.color = color
# Objects of class
Sentence = Example4(20, "brown")
Sentence2 = Example4(20, "brown")
print('Sentence details:')
print('She is: ', Sentence.name)
print('Age: ', Sentence.age)
print('Color: ', Sentence.color)
print('\nSentence 2 details:')
print('He is: ', Sentence2.name)
print('Age: ', Sentence2.age)
print('Color: ', Sentence2.color)
# Class variables can be accessed using class
# name also
print("\nAccessing class variable using class name")
print(Example4.name)