Python Quiz

Descripción

A beginners quiz to aid learning Python.
karljmurphy
Test por karljmurphy, actualizado hace más de 1 año
karljmurphy
Creado por karljmurphy hace más de 9 años
733
25

Resumen del Recurso

Pregunta 1

Pregunta
Examine the code and determine the value of the variable b when the code completes.
Respuesta
  • 6
  • 2
  • None

Pregunta 2

Pregunta
Examine the code and determine the output.
Respuesta
  • {}
  • foo
  • {'obj_name': 'foo'}
  • {'obj_name' = 'foo'}

Pregunta 3

Pregunta
What output will be produced from this snippet of code?
Respuesta
  • IndexError
  • []
  • ['a', 'b', 'c', 'd', 'e']

Pregunta 4

Pregunta
What is the difference between a tuple and a list?
Respuesta
  • A tuple is immutable and a list is mutable.
  • A list is immutable and a tuple is mutable.

Pregunta 5

Pregunta
What output will be produced?
Respuesta
  • in except block
  • in except block after try-except

Pregunta 6

Pregunta
Is a list a heterogeneous data structure in Python?
Respuesta
  • Yes
  • No

Pregunta 7

Pregunta
If a list is mutable in Python, can it hold immutable objects?
Respuesta
  • Yes
  • No

Pregunta 8

Pregunta
A tuple is an immutable data structure in Python. Can it hold mutable objects?
Respuesta
  • No
  • Yes

Pregunta 9

Pregunta
What is the value of variable d when the code completes?
Respuesta
  • [1, 'Dublin', 2, 'London', 3, 'Moscow']
  • {1: 'Dublin', 2: 'London', 3: 'Moscow'}
  • An exception is raised

Pregunta 10

Pregunta
Is the code performing legal operations?
Respuesta
  • Yes
  • No

Pregunta 11

Pregunta
Do a and b return the same object type?
Respuesta
  • No
  • Yes

Pregunta 12

Pregunta
Determine the value of the variable b when the code completes?
Respuesta
  • [10,20,30]
  • 20
  • [10, 20, 50]

Pregunta 13

Pregunta
What is the output from this code?
Respuesta
  • False
  • True

Pregunta 14

Pregunta
What is the output of the code?
Respuesta
  • 15
  • 25
  • True

Pregunta 15

Pregunta
What is the output of the code?
Respuesta
  • 'age under 30'
  • 'age equals 25'
  • None of the above

Pregunta 16

Pregunta
Determine the output of the code?
Respuesta
  • {house:1215}, 'apt
  • An exception is raised
  • 'apt', {house:1215}

Pregunta 17

Pregunta
What is the output?
Respuesta
  • 0 2
  • john sarah
  • An exception is raised

Pregunta 18

Pregunta
Which line of code is correct to detect if a variable is a function?
Respuesta
  • hasattr(obj, '__call__')
  • isinstance(x, function)
  • type(x) == 'function'

Pregunta 19

Pregunta
What is PEP 8?
Respuesta
  • It runs Python bytecode
  • It is a data structure
  • It is a code style guideline

Pregunta 20

Pregunta
What is the value of the variable name when the code completes?
Respuesta
  • Kim
  • Sam

Pregunta 21

Pregunta
What is the "__init__.py" file for in a Python source directory?
Respuesta
  • It's a constructor
  • Marks a directory as a Python package

Pregunta 22

Pregunta
Is new_list a shallow or deep copy of old_list?
Respuesta
  • shallow
  • deep

Pregunta 23

Pregunta
Determine what the output will be?
Respuesta
  • ['j','o','h','n']
  • 'John'
  • 'mylist'

Pregunta 24

Pregunta
What is the output of the code?
Respuesta
  • list
  • set
  • dictionary

Pregunta 25

Pregunta
Determine the value of a after the method is called twice.
Respuesta
  • [10, 10]
  • []
  • [10]

Pregunta 26

Pregunta
Determine the output of the code?
Respuesta
  • 50
  • 40
  • 70

Pregunta 27

Pregunta
What is the output of the code?
Respuesta
  • 'Sar'
  • 'Sarah'
  • 'Sa'

Pregunta 28

Pregunta
What is the output of the code?
Respuesta
  • None
  • 4

Pregunta 29

Pregunta
I want to read from a file on the path 'C:\newfile\textfile.txt'. What is the correct way to open the file?
Respuesta
  • myfile = open('C:\newfile\textfile.txt', 'r')
  • myfile = open(r'C:\newfile\textfile.txt', 'r')

Pregunta 30

Pregunta
Review the code. Does the variable a have a type? If so, what is the type of a?
Respuesta
  • Variable a does not have a type
  • Variable a is of type List
  • Variable a is of type String

Pregunta 31

Pregunta
Is that code legal?
Respuesta
  • Yes
  • No

Pregunta 32

Pregunta
Determine the result?
Respuesta
  • 2
  • 1

Pregunta 33

Pregunta
Is the code legal or illegal?
Respuesta
  • legal
  • illegal

Pregunta 34

Pregunta
What is the result of the code?
Respuesta
  • 'today'
  • 'TODAY'
  • 'str'

Pregunta 35

Pregunta
What output does the code produce?
Respuesta
  • ['jack', 'peter', 'sarah']
  • ['sarah']
  • [ 'sarah', 'peter', jack']

Pregunta 36

Pregunta
Analyse the code and determine the result
Respuesta
  • Infinite loop
  • The code prints the following: 2 Joe
  • The code prints the following: 1 2 Mary

Pregunta 37

Pregunta
What is the output?
Respuesta
  • [10]
  • raises an exception
  • [[10]]

Pregunta 38

Pregunta
What object types do variables a and b point to?
Respuesta
  • a and b point to a tuple
  • a points to an int; b points to a tuple
  • a and b point to an int
Mostrar resumen completo Ocultar resumen completo

Similar

HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Historical Development of Computer Languages
Shannon Anderson-Rush
Useful String Methods
Shannon Anderson-Rush
Flvs foundations of programming dba 2
mariaha vassar
Think Python
tsilvo2001
What is Python?
Daniel Ingram
Python
54671
Angular
Kingsley Bawuah
Basic Python - Strings
Rebecca Noel
Computer Science
Luke Broadley