Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

reference variable python

// no need to define variables explicitly like in java or c++
// we need to define them in __init__ method that creates, this i8s the key 
// __init__ basically it's constructor
// instance variables for the current object self( which denotes your created instance)
class A:
 def __init__(self,d):
     self.d=d
//above automaticaaly creates an instance variable d for you class object
hence 

ob=A(4)
// creates object ob with 1 instance variable d initialised to 4 

ALSO NOTE:
// in python there is no distinction between pointer variable and 
// normal variable we use same syntax for both unlike c++
// so how python distinguishes b/w a reference and normal var?
// by seeing what is being assigned to it on RHS
Source by openclassrooms.com #
 
PREVIOUS NEXT
Tagged: #reference #variable #python
ADD COMMENT
Topic
Name
3+4 =