Python Quiz

Descrição

A beginners quiz to aid learning Python.
karljmurphy
Quiz por karljmurphy, atualizado more than 1 year ago
karljmurphy
Criado por karljmurphy aproximadamente 9 anos atrás
719
25

Resumo de Recurso

Questão 1

Questão
Examine the code and determine the value of the variable b when the code completes.
Responda
  • 6
  • 2
  • None

Questão 2

Questão
Examine the code and determine the output.
Responda
  • {}
  • foo
  • {'obj_name': 'foo'}
  • {'obj_name' = 'foo'}

Questão 3

Questão
What output will be produced from this snippet of code?
Responda
  • IndexError
  • []
  • ['a', 'b', 'c', 'd', 'e']

Questão 4

Questão
What is the difference between a tuple and a list?
Responda
  • A tuple is immutable and a list is mutable.
  • A list is immutable and a tuple is mutable.

Questão 5

Questão
What output will be produced?
Responda
  • in except block
  • in except block after try-except

Questão 6

Questão
Is a list a heterogeneous data structure in Python?
Responda
  • Yes
  • No

Questão 7

Questão
If a list is mutable in Python, can it hold immutable objects?
Responda
  • Yes
  • No

Questão 8

Questão
A tuple is an immutable data structure in Python. Can it hold mutable objects?
Responda
  • No
  • Yes

Questão 9

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

Questão 10

Questão
Is the code performing legal operations?
Responda
  • Yes
  • No

Questão 11

Questão
Do a and b return the same object type?
Responda
  • No
  • Yes

Questão 12

Questão
Determine the value of the variable b when the code completes?
Responda
  • [10,20,30]
  • 20
  • [10, 20, 50]

Questão 13

Questão
What is the output from this code?
Responda
  • False
  • True

Questão 14

Questão
What is the output of the code?
Responda
  • 15
  • 25
  • True

Questão 15

Questão
What is the output of the code?
Responda
  • 'age under 30'
  • 'age equals 25'
  • None of the above

Questão 16

Questão
Determine the output of the code?
Responda
  • {house:1215}, 'apt
  • An exception is raised
  • 'apt', {house:1215}

Questão 17

Questão
What is the output?
Responda
  • 0 2
  • john sarah
  • An exception is raised

Questão 18

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

Questão 19

Questão
What is PEP 8?
Responda
  • It runs Python bytecode
  • It is a data structure
  • It is a code style guideline

Questão 20

Questão
What is the value of the variable name when the code completes?
Responda
  • Kim
  • Sam

Questão 21

Questão
What is the "__init__.py" file for in a Python source directory?
Responda
  • It's a constructor
  • Marks a directory as a Python package

Questão 22

Questão
Is new_list a shallow or deep copy of old_list?
Responda
  • shallow
  • deep

Questão 23

Questão
Determine what the output will be?
Responda
  • ['j','o','h','n']
  • 'John'
  • 'mylist'

Questão 24

Questão
What is the output of the code?
Responda
  • list
  • set
  • dictionary

Questão 25

Questão
Determine the value of a after the method is called twice.
Responda
  • [10, 10]
  • []
  • [10]

Questão 26

Questão
Determine the output of the code?
Responda
  • 50
  • 40
  • 70

Questão 27

Questão
What is the output of the code?
Responda
  • 'Sar'
  • 'Sarah'
  • 'Sa'

Questão 28

Questão
What is the output of the code?
Responda
  • None
  • 4

Questão 29

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

Questão 30

Questão
Review the code. Does the variable a have a type? If so, what is the type of a?
Responda
  • Variable a does not have a type
  • Variable a is of type List
  • Variable a is of type String

Questão 31

Questão
Is that code legal?
Responda
  • Yes
  • No

Questão 32

Questão
Determine the result?
Responda
  • 2
  • 1

Questão 33

Questão
Is the code legal or illegal?
Responda
  • legal
  • illegal

Questão 34

Questão
What is the result of the code?
Responda
  • 'today'
  • 'TODAY'
  • 'str'

Questão 35

Questão
What output does the code produce?
Responda
  • ['jack', 'peter', 'sarah']
  • ['sarah']
  • [ 'sarah', 'peter', jack']

Questão 36

Questão
Analyse the code and determine the result
Responda
  • Infinite loop
  • The code prints the following: 2 Joe
  • The code prints the following: 1 2 Mary

Questão 37

Questão
What is the output?
Responda
  • [10]
  • raises an exception
  • [[10]]

Questão 38

Questão
What object types do variables a and b point to?
Responda
  • a and b point to a tuple
  • a points to an int; b points to a tuple
  • a and b point to an int

Semelhante

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