-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.py
More file actions
38 lines (30 loc) · 742 Bytes
/
objects.py
File metadata and controls
38 lines (30 loc) · 742 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
class PlayerCharacter:
# __init__ is a dunder method that acts as a constructor
def __init__(self, name, age):
self.name = name
self.age = age
def run(self):
print('run')
return 'executed run()'
player1 = PlayerCharacter('Ram', 25)
player2 = PlayerCharacter('Roop', 24)
print(player1) # memory location of the object
print(player1.run()) # run \nexecuted run()
print(player2)
print(player2.run())
print(player2.age)
# We can also add properties to certain instances as follows:
player2.attack = 40
print(player2.attack)
'''
Output:
------
<__main__.PlayerCharacter object at 0x00E29118>
run
executed run()
<__main__.PlayerCharacter object at 0x00E29160>
run
executed run()
24
40
'''