Python Quiz

Description

A beginners quiz to aid learning Python.
karljmurphy
Quiz by karljmurphy, updated more than 1 year ago
karljmurphy
Created by karljmurphy about 9 years ago
718
25

Resource summary

Question 1

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

Question 2

Question
Examine the code and determine the output.
Answer
  • {}
  • foo
  • {'obj_name': 'foo'}
  • {'obj_name' = 'foo'}

Question 3

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

Question 4

Question
What is the difference between a tuple and a list?
Answer
  • A tuple is immutable and a list is mutable.
  • A list is immutable and a tuple is mutable.

Question 5

Question
What output will be produced?
Answer
  • in except block
  • in except block after try-except

Question 6

Question
Is a list a heterogeneous data structure in Python?
Answer
  • Yes
  • No

Question 7

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

Question 8

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

Question 9

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

Question 10

Question
Is the code performing legal operations?
Answer
  • Yes
  • No

Question 11

Question
Do a and b return the same object type?
Answer
  • No
  • Yes

Question 12

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

Question 13

Question
What is the output from this code?
Answer
  • False
  • True

Question 14

Question
What is the output of the code?
Answer
  • 15
  • 25
  • True

Question 15

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

Question 16

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

Question 17

Question
What is the output?
Answer
  • 0 2
  • john sarah
  • An exception is raised

Question 18

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

Question 19

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

Question 20

Question
What is the value of the variable name when the code completes?
Answer
  • Kim
  • Sam

Question 21

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

Question 22

Question
Is new_list a shallow or deep copy of old_list?
Answer
  • shallow
  • deep

Question 23

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

Question 24

Question
What is the output of the code?
Answer
  • list
  • set
  • dictionary

Question 25

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

Question 26

Question
Determine the output of the code?
Answer
  • 50
  • 40
  • 70

Question 27

Question
What is the output of the code?
Answer
  • 'Sar'
  • 'Sarah'
  • 'Sa'

Question 28

Question
What is the output of the code?
Answer
  • None
  • 4

Question 29

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

Question 30

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

Question 31

Question
Is that code legal?
Answer
  • Yes
  • No

Question 32

Question
Determine the result?
Answer
  • 2
  • 1

Question 33

Question
Is the code legal or illegal?
Answer
  • legal
  • illegal

Question 34

Question
What is the result of the code?
Answer
  • 'today'
  • 'TODAY'
  • 'str'

Question 35

Question
What output does the code produce?
Answer
  • ['jack', 'peter', 'sarah']
  • ['sarah']
  • [ 'sarah', 'peter', jack']

Question 36

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

Question 37

Question
What is the output?
Answer
  • [10]
  • raises an exception
  • [[10]]

Question 38

Question
What object types do variables a and b point to?
Answer
  • a and b point to a tuple
  • a points to an int; b points to a tuple
  • a and b point to an int
Show full summary Hide full summary

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