Part 2 Summary Test
Part 2 Summary Test
Part 2 Summary Test
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test
Progress (100%)
Item 1/30
prints 1.3
The following code:
prints l, 3
Next 4
Progress (100%)
Item 2/30
has no effect
The following statement:
a33ert var !— 0
wifi stop the program when var = o
is erroneous
Next 4
Progress (100%)
Item 3/30
try:
raise Exception b
except:
print fc")
except Base Except ion:
a
print {"a")
except Exception:
print rb")
*Prev Next*
Progress (100%)
Item 4/30
it will print 2
What will be the result of executing the following code?
try:
it will print 3
rai3e Except icn (lj, 2r 3}
except .Exception as e:
print {len(e . aigs) J
it wifi print l
*Prev Next*
Progress (100%)
Item 5/30
q = 3. read (1)
one buffer from the stream
will read:
Next*
Progress (100%)
Item 6/30
clas3 A:
def {self) : it will print False
pa33
a F A(l}
print (ha3attr {a, 'A1)) it will raise an exception
it wifi print l
Next
Progress (100%)
Item 7/30
it wit] print *
What will be the result of executing the following code?
def o (p):
def q<> : it will print
1 1 ■
return * P
return q
it will print
Next
Progress (100%)
Item 8/30
Next
Progress (100%)
Item 9/30
*Prev Next*
Progress (100%)
item 10/30
a null device
The sys.Btderr stream is normally associated with:
the screen
the printer
the keyboard
Next*
Progress (100%)
item 11/30
clas3 A:
pd33
it wifi print l
clas3 E (A) :
pa33
it will print False
clas3 C (B) :
pa33
Next
Progress (100%)
item 12/30
it wit] print
What will be the result of executing the following code?
def I(n):
3 — T
+' it will print +
for i in range (n):
3 += 3
yield 3
it witi print +++
for x in I(2):
I
1
prints, end= }
it will print ++
*Prev Next*
Progress (100%)
item 13/30
*Prev Next*
Progress (100%)
item 14/30
clas3 A:
def a {self) : it wifi print a
print ('a')
da 33 E:
def a {self) : it witl print c
print (,b')
Next
o = C()
o.c() *
Retake Test Back to Summary
PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test
Progress (100%)
item 15/30
clas3 r :
def _ init _ {self) :
it will print cba
self. 3 = 1
abc 1
self . i = 0
def iter {self) :
return 3elf it will print abc
def next {self) :
if 3elf.i = len(self.s):
raise Stcplteration
v = self .s [self.i] it will print 012
self.i += 1
return v
Progress (100%)
item 16/30
_P-PY_
What will be the output of the following code, located in the p.py file?
print ( name .)
p.py
main
o main
Next
Progress (100%)
item 17/30
prints 3
The following code:
x = "WW"
print (len{x)) will cause an error
prints l
prints 3
*Prev Next*
Progress (100%)
item 18/30
clas3 A:
def {3elf , v): it will print 2
self. a - v + 1
a Ff A(0)
print (a . _ a) it wit! print l
it will print o
*Prev Next*
Progress (100%)
item 19/30
mod:fun(}
Knowing that a function named fun[) resides in a module named mod and was
r
mod.fun(}
mod:: fun ()
Next
Progress (100%)
item 20/30
*Prev Next*
Progress (100%)
item 21/30
1
What will be the output of the following code?
clas3 A:
A = 1 False
def _ init _ {3elf) :
self. a = 0
True
Next
Progress (100%)
item 22/30
t
The following code prints:
*Prev Next*
Progress (100%)
item 23/30
prints 1
The following code:
x — "\\\*
print (len{x)) prints 2
prints 3
Next
Progress (100%)
item 24/30
object = Cias3(None)
If the class's constructor is declared as below, which one of the assignments is invalid?
clas3 C 2 a ss :
def {self, val=0): object = Class (1, 2)
pa33
object = Clas3(l)
object = Clas3(J
Next
Progress (100%)
item 25/30
import math
print (dir{math)) a list of all the entities residing in the math module
an error message
Next 4
Progress (100%)
item 26/30
abc
Assuming that the following three files: a.py r b.py.and c.py reside in the same
folder, what will be the output produced after ru nning the c .py file?
bac
# file a, py
print ("a", end— i r )
#f lie b.py
cba
import a
I P
print ("b'\ end: )
#file c.py
print ("c", end='')
import a
o cab
import b
Next
Progress (100%)
item 27/30
clas3 A:
def {self, v=2) : 1
self.v = v
return self.v
a = A{)
b M a 2
b.a et {)
print (a . v)
Next
Progress (100%)
Item 28/30
py
The compiled Python bytecode is stored in files which have their names ending with:
pc
Q pyc
pyb
Next
Progress (100%)
Item 29/30
1
for x in open('file', rt 1 ) :
print {x)
read the whole file at once
cause an exception
Next*
Progress (100%)
Item 30/30
41 Prev