CBSE computer and communication technology
Sponsor Area
How is __init__() different from __del__() ?
__init__() is the class constructor or initialization method which is automatically invoked when we create a new instance of a class.
__del__() is a destructor which is automatically invoked when an object (instance) goes out of scope.
For Example:
class Sample:
def __init__(self):
self.data = 79
print('Data:',self.data,'created')
def __del__(self):
print('Data:',self.data,'deleted')
s = Sample()
del s
Sponsor Area
Name the function/method required to
- check if a string contains only uppercase letters
- gives the total length of the list.
Required Function
- isupper()
- len()
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
def Tot(Number) #Method to find Total
Sum=0
for C in Range (1, Number+1):
Sum+=C
RETURN Sum
print Tot[3] #Function Calls
print Tot[6]
def Tot(Number): #Method to find Total #Error 1
Sum=0
for C in range (1, Number+1): #Error 2
Sum+=C
return Sum #Error 3
print Tot(3) #Function Call #Error 4
print Tot(6) #Error 4
Find and write the output of the following python code :
for Name in ['Jayes', 'Ramya', 'Taruna','Suraj']:
print Name
if Name[0]== 'T':
break
else :
print 'Finished!'
print 'Got it!'
Jayes
Ramya
Taruna
Got it!
Find and write the output of the following python code:
class Worker :
def_init_(self,id,name): #constructor
self.ID=id
self.NAME=name
def Change (self):
self.ID=self.ID+10
self.NAME='Harish'
def Display(self,ROW):
print self.ID,self.NAME,ROW
w=Worker(55,'Fardeen')
w.Display(l)
w.Change( )
w.Display(2)
print w.ID+len(w.NAME)
Output:
55 Fardeen 1
65 Harish 2
71
Sponsor Area
Mock Test Series
Mock Test Series



