What sequence of numbers is printed?
values = [1, 2, 1, 3]
nums = set(values)
def checkit(num):
if num in nums:
return True
else:
return False
for i in filter(checkit, values):
print i
Answer
Which numbers are printed?
for i in range(2):
print i
for i in range(4,6):
print i
Answer
What gets printed?
name = "snow storm"
name[5] = 'X'
print name
Answer
What gets printed?
name = "snow storm"
print "%s" % name[6:8]
Answer
What gets printed?
class Account:
def __init__(self, id):
self.id = id
id = 666
acc = Account(123)
print acc.id
Answer
What gets printed?
kvps = {"user","bill", "password","hillary"}
print kvps['password']
Answer
What gets printed?
class parent:
def __init__(self, param):
self.v1 = param
class child(parent):
def __init__(self, param):
self.v2 = param
obj = child(11)
print "%d %d" % (obj.v1, obj.v2)
Answer
What gets printed?
print 0xA + 0xa
Answer
What gets printed?
print "\x48\x49!"
Answer
What gets printed?
Assume Python 2
print "hello" 'world'
Answer
What gets printed?
print r"\nwoow"
Answer
What gets printed?
counter = 1
def doLotsOfStuff():
global counter
for i in (1, 2, 3):
counter += 1
doLotsOfStuff()
print counter
Answer
Assuming python 2.6 what gets printed?
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print f.closed
Answer
The following code will successfully print the days and then the months
daysOfWeek = ['Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday']
months = ['Jan', \
'Feb', \
'Mar', \
'Apr', \
'May', \
'Jun', \
'Jul', \
'Aug', \
'Sep', \
'Oct', \
'Nov', \
'Dec']
print "DAYS: %s, MONTHS %s" %
(daysOfWeek, months)
Answer
In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type or SecurityError type
try:
accessSecureSystem()
except AccessError, SecurityError:
print "error type 1"
continueWork()
Answer
If PYTHONPATH is set in the environment, which directories are searched for modules?
A) PYTHONPATH directory
B) current directory
C) home directory
D) installation dependent default path
Answer
What gets printed?
x = True
y = False
z = False
if not x or y:
print 1
elif not x or not y and z:
print 2
elif not x or y or not y and x:
print 3
else:
print 4
Answer
What gets printed?
x = True
y = False
z = False
if x or y and z:
print "yes"
else:
print "no"
Answer
What gets printed?
nums = set([1,1,2,3,3,3,4])
print len(nums)
Answer
What gets printed?
x = 4.5
y = 2
print x//y
Answer
© 2017 QuizBucket.org