Module 1 Flashcards
What will x be after the following statement?
x = [n**3 for n in range (4)]
a.
[0, 1, 3, 9]
b.
[0,1, 8, 27]
c.
[0, 3, 9, 27]
d.
none of the above
b.
[0,1, 8, 27]
Which statement is illegal in Python?
a.
x = {(10,), (20,)}
b.
y = {[10],[20]}
c.
z = {10,20}
d.
all are legal
b.
y = {[10],[20]}
x = [10 , 20, 30]
y = x
print(id(x) == id(y))
True or False?
True
If you wanted to find the standard Euclidean distance between two vectors, you would find the p-norm of their difference, with p equal to what value?
a.
p = 1/2
b.
p = 1
c.
p = infinity
d.
p = 2
d.
p = 2
Which of the following does not exist in Python?
a.
list comprehension
b.
tuple comprehension
c.
set comprehension
d.
dictionary comprehension
b.
tuple comprehension
What is the output after the following statements of the print?
z = “university”
print (z [::-1][1:4])
a.
“tis”
b.
“isr”
c.
“ive”
d.
“niv”
a.
“tis”
m = {10:20, 30:40}
for x, y in m.items ():
print (x, y, end=” “)
a.
{10:20, 30:40}
b.
10 30 20 40
c.
10:20, 30:40
d.
10 20 30 40
d.
10 20 30 40
What is the result of the following:
def f(n):
if n==1:
return 1
else:
return 2**n*f(n-1)
print(f(3))
a.
24
b.
16
c.
32
d.
36
c.
32
What is the output after the following:
x = [[10] , 20]
y = x. copy ()
y [0][0] = 100
print (x, y)
a.
[[10]; 20] [[10]; 20]
b.
[[100]; 20] [[10]; 20]
c.
[[100]; 20] [[100]; 20]
d.
[[10]; 20] [[100]; 20]
c.
[[100]; 20] [[100]; 20]
What will be y after the following statement?
x = “Wednesday”
y = x [1:5][100:500] + x [2::4]
a.
error
b.
[“d”, “d”]
c.
“dn”
d.
[“d”, “n”]
e.
“dd”
e.
“dd”