forked from officialtech/xPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance_variable | python
More file actions
41 lines (24 loc) · 1.43 KB
/
instance_variable | python
File metadata and controls
41 lines (24 loc) · 1.43 KB
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
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> INSTANCE VARIABLES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1.The variables which are declared inside the method using self word is called instance variable.
2. The variables which holds the unique values for every object.
3. Instance variables will get memory for every object.
4. To call instance variables we use object variable.
5. Instance variables will get memory after object creation.
Syntax:-
class_name()
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ OBJECT $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Object is an instance of a class. Instance means allocating sufficient memory for a instance variable of a class. $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
___________________________________________ Program on instance variables _________________________________________________
class Student: # class
def assignment(self): # instance method
self.id = 1010 # instance variable
self.name = 'jin' # instance variable
self.contact = 10010101000010 # instance variable
def display(self):
print(self.id)
print(self.name)
print(self.contact)
s = Student()
s.assignment()
s.display()