Chapter Five : Object Life Cycle

Example 5.1 page no: 32

In [1]:
i = 10;
j = 10;

Example 5.2 page no : 33

In [2]:
string1 = "hello";
string2 = "hello"; 
print string1, string2
hello hello

EXAMPLE 5.3 page no : 33

In [3]:
i = int(raw_input()) # no reason to initialize i
print i
5
5

EXAMPLE 5.4 page no : 34

In [4]:
oldLm = 0;
newLm = 0;

EXAMPLE 5.5 page no : 34

In [5]:
charMapSize = 256;
for i in range(charMapSize):
    pass

EXAMPLE 5.6 page no : 36

In [6]:
class Base:
    def __init__(self,i=0):
        self.iM = 0

class Derived(Base):
    def __init__(self,i=0):
        Base.__init__(self,i)
        self.jM = i

EXAMPLE 5.7 page no : 37

In [7]:
class Base:
    def __init__(self,i=0):
        self.iM = 0

class Derived(Base):
    def __init__(self,i=0):
        self.jM = i
        bm = Base(i)

example 5.8 page no : 40

In [8]:
def dangerous():
    i = 5;
    return i
j = dangerous(); # NO: j is dangerous to use
print j;
5

EXAMPLE 5.9 page no : 41

In [9]:
class CommunicationPort:
    def __init__(self,port):
        pass
    
    def __del__(self):
        pass

EXAMPLE 5.10 page no : 42

In [10]:
class EmcIntStack:
    def __init__(self,d):
        self.allocatedM = d
        self.vectorM = []

    def __del__():
        pass   

example 5.11 page no : 43

In [11]:
s = "Aguirre";
s = s;
print s 
Aguirre

example 5.12 page no : 43

In [12]:
s = "Aguirre";
r = s;
print r
Aguirre
In [ ]: