File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed
Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 1- #Author: OMKAR PATHAK
2- #In this example we will be seeing how instance Attributes are used
3- #Instance attributes are accessed by: object.attribute
4- #Attributes are looked First in the instance and THEN in the class
1+ # Author: OMKAR PATHAK
2+ # Demonstration of Instance Attributes
53
64import random
7- class Vehicle ():
8- #Class Methods/ Attributes
5+
6+ class Vehicle :
7+
98 def type (self ):
10- #NOTE: This is not a class attribute as the variable is binded to self. Hence it becomes
11- #instance attribute
12- self .randomValue = random .randint (1 ,10 ) #Setting the instance attribute
9+ # Creating instance attribute
10+ self .randomValue = random .randint (1 , 10 )
1311
12+ # Creating object
1413car = Vehicle ()
15- car .type () #Calling the class Method
16- print (car .randomValue ) #Calling the instance attribute
14+
15+ # Calling method
16+ car .type ()
17+
18+ # Accessing instance attribute
19+ print ("Random Value:" , car .randomValue )
You can’t perform that action at this time.
0 commit comments