What is the output of the following code snippet: (You can see the picture too)
if 'bar' in {'foo': 1, 'bar': 2, 'baz': 3}:
print(1)
print(2)
if 'a' in 'qux':
print(3)
print(4)
d = dict([
('foo', 100),
('bar', 200),
('baz', 300)
])
Questão 4
Questão
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
Responda
a[2] = []
del a[2]
a.add(3)
a[0:3] = []
a[2:2] = []
Questão 5
Questão
Which of the following would separate a string input_string on the first 2 occurences of the letter “e”?
Responda
input_string.split('e', 2)
'e'.split(input_string, maxsplit=2)
'e'.split(input_string, 2)
Questão 6
Questão
What is the output of the following code snippet:
d = {'foo': 1, 'bar': 2, 'baz': 3}
while d:
print(d.popitem())
print('Done.')
The function sqrt() from the math module computes the square root of a number.
Will the highlighted line of code raise an exception?
x = -100
from math import sqrt
x > 0 and sqrt(x)
Which of the following mathematical operators can be used to concatenate strings:
Responda
+
*
/
-
Questão 9
Questão
Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':
Responda
It’s a trick question—tuples can’t be modified.
t(1) = 'qux'
t[1:1] = 'qux'
t[1] = 'qux'
Questão 10
Questão
What is value of this expression:
'a' + 'x' if '123'.isdigit() else 'y' + 'b'