Pre-Test (Python Basic)

Descripción

Test sobre Pre-Test (Python Basic), creado por Mohammed Arif Mazumder el 02/07/2021.
Mohammed Arif Mazumder
Test por Mohammed Arif Mazumder, actualizado hace más de 1 año
Mohammed Arif Mazumder
Creado por Mohammed Arif Mazumder hace más de 3 años
1804
0

Resumen del Recurso

Pregunta 1

Pregunta
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)
Respuesta
  • 1 2 3 4
  • 1 2 4
  • It doesn’t generate any output.
  • 4

Pregunta 2

Pregunta
The following if/elif/else statement will raise a KeyError exception: d = {'a': 0, 'b': 1, 'c': 0} if d['a'] > 0: print('ok') elif d['b'] > 0: print('ok') elif d['c'] > 0: print('ok') elif d['d'] > 0: print('ok') else: print('not ok')
Respuesta
  • True
  • False

Pregunta 3

Pregunta
Shown below is a diagram of a simple dictionary: Which of the following is not a valid way to define this dictionary in Python:
Respuesta
  • d = {'foo': 100, 'bar': 200, 'baz': 300}
  • d = { ('foo', 100), ('bar', 200), ('baz', 300) }
  • d = {} d['foo'] = 100 d['bar'] = 200 d['baz'] = 300
  • d = dict(foo=100, bar=200, baz=300)
  • d = dict([ ('foo', 100), ('bar', 200), ('baz', 300) ])

Pregunta 4

Pregunta
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]:
Respuesta
  • a[2] = []
  • del a[2]
  • a.add(3)
  • a[0:3] = []
  • a[2:2] = []

Pregunta 5

Pregunta
Which of the following would separate a string input_string on the first 2 occurences of the letter “e”?
Respuesta
  • input_string.split('e', 2)
  • 'e'.split(input_string, maxsplit=2)
  • 'e'.split(input_string, 2)

Pregunta 6

Pregunta
What is the output of the following code snippet: d = {'foo': 1, 'bar': 2, 'baz': 3} while d: print(d.popitem()) print('Done.')
Respuesta
  • Done.
  • foo bar baz
  • The snippet doesn’t generate any output.
  • ('baz', 3) ('bar', 2) ('foo', 1) Done.

Pregunta 7

Pregunta
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)
Respuesta
  • True
  • False

Pregunta 8

Pregunta
Which of the following mathematical operators can be used to concatenate strings:
Respuesta
  • +
  • *
  • /
  • -

Pregunta 9

Pregunta
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':
Respuesta
  • It’s a trick question—tuples can’t be modified.
  • t(1) = 'qux'
  • t[1:1] = 'qux'
  • t[1] = 'qux'

Pregunta 10

Pregunta
What is value of this expression: 'a' + 'x' if '123'.isdigit() else 'y' + 'b'
Respuesta
  • 'ab'
  • 'axb'
  • 'ax'
  • 'axyb'
Mostrar resumen completo Ocultar resumen completo

Similar

PERSONAJES...
JL Cadenas
Inglés - Repaso de Preposiciones
maya velasquez
Romanticismo literario del S. XIX
maya velasquez
Diferencias entre la Química y Física
maya velasquez
LA METODOLOGÍA DE LAS BASES DE DATOS
Fernando Tapia
Cáncer de Mama
Luz Moor
Ley Orgánica de la Administración Pública Federal.
Miguel Guizar
Análisis de una Pintura
Diego Santos
Enlaces Químicos
Camila Barbosa
DERECHO ADMINISTRATIVO II
Alfonso Tester
USO DE HERRAMIENTAS DE DISEÑO AUTOCAD
mart cruzz