Python Quiz

Beschreibung

A beginners quiz to aid learning Python.
karljmurphy
Quiz von karljmurphy, aktualisiert more than 1 year ago
karljmurphy
Erstellt von karljmurphy vor mehr als 9 Jahre
753
25

Zusammenfassung der Ressource

Frage 1

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

Frage 2

Frage
Examine the code and determine the output.
Antworten
  • {}
  • foo
  • {'obj_name': 'foo'}
  • {'obj_name' = 'foo'}

Frage 3

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

Frage 4

Frage
What is the difference between a tuple and a list?
Antworten
  • A tuple is immutable and a list is mutable.
  • A list is immutable and a tuple is mutable.

Frage 5

Frage
What output will be produced?
Antworten
  • in except block
  • in except block after try-except

Frage 6

Frage
Is a list a heterogeneous data structure in Python?
Antworten
  • Yes
  • No

Frage 7

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

Frage 8

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

Frage 9

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

Frage 10

Frage
Is the code performing legal operations?
Antworten
  • Yes
  • No

Frage 11

Frage
Do a and b return the same object type?
Antworten
  • No
  • Yes

Frage 12

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

Frage 13

Frage
What is the output from this code?
Antworten
  • False
  • True

Frage 14

Frage
What is the output of the code?
Antworten
  • 15
  • 25
  • True

Frage 15

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

Frage 16

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

Frage 17

Frage
What is the output?
Antworten
  • 0 2
  • john sarah
  • An exception is raised

Frage 18

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

Frage 19

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

Frage 20

Frage
What is the value of the variable name when the code completes?
Antworten
  • Kim
  • Sam

Frage 21

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

Frage 22

Frage
Is new_list a shallow or deep copy of old_list?
Antworten
  • shallow
  • deep

Frage 23

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

Frage 24

Frage
What is the output of the code?
Antworten
  • list
  • set
  • dictionary

Frage 25

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

Frage 26

Frage
Determine the output of the code?
Antworten
  • 50
  • 40
  • 70

Frage 27

Frage
What is the output of the code?
Antworten
  • 'Sar'
  • 'Sarah'
  • 'Sa'

Frage 28

Frage
What is the output of the code?
Antworten
  • None
  • 4

Frage 29

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

Frage 30

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

Frage 31

Frage
Is that code legal?
Antworten
  • Yes
  • No

Frage 32

Frage
Determine the result?
Antworten
  • 2
  • 1

Frage 33

Frage
Is the code legal or illegal?
Antworten
  • legal
  • illegal

Frage 34

Frage
What is the result of the code?
Antworten
  • 'today'
  • 'TODAY'
  • 'str'

Frage 35

Frage
What output does the code produce?
Antworten
  • ['jack', 'peter', 'sarah']
  • ['sarah']
  • [ 'sarah', 'peter', jack']

Frage 36

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

Frage 37

Frage
What is the output?
Antworten
  • [10]
  • raises an exception
  • [[10]]

Frage 38

Frage
What object types do variables a and b point to?
Antworten
  • a and b point to a tuple
  • a points to an int; b points to a tuple
  • a and b point to an int
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

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