wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 133

Worksheet time: 1hrs 7mins

Name
Class
Date
1.

In which of the following does the Cricket Fan class correctly inherit from the Party Animal class?

a)

from party import Party Animal

b)

class CricketFan(PartyAnimal)

c)

An= PartyAnimal()

d)

CricketFan = PartyAnimal()

2.

In Python, a class is... for a concrete object.

a)

nuisance

b)

instance

c)

blueprint

d)

distraction

3.

Which of the following is the correct way to define an initializer method?

a)

def init(title, author):

b)

def init(self, title, author):

c)

def init():

d)

init(self, title, author):

4.

What keyword is used to indicate the start of a method in a Python class?

a)

def

b)

break

c)

function

d)

continue

5.

Which of the following statements is not true about object-oriented programming?

a)

One of the benefits of object-oriented programming is that it can hide complexity.

b)

A class contains functions as well as the data that is used by those functions.

c)

Constructor methods are required to initialize an object and destructor methods are required to destroy the object when no longer required.

d)

A powerful feature of object-oriented programming is the ability to create a new class by extending an existing class.

6.

What is the output of the following code? python class Person: def_init__(self, id): self.id =id sam Person(100) sam_dict_['age'] $I=49$ print(sam.age len(sam._dict))

a)

49

b)

50

c)

51

d)

48

7.

Which came first, the instance or the class?

a)

Class

b)

Function

c)

Instance

d)

Method

8.

What's the output of the following code snippet? python class Dog: def walk(self): return "walking" def speak(self): return "Woof!" class Jack Russell Terrier(Dog): def talk(self): return super().speak() bobo JackRussell Terrier() bobo.talk()

a)

Woof!

b)

walking

c)

CanineError: Tail curvature exceeded

d)

None of the others

9.

Which of the following code uses the inheritance feature of Python?

a)

Class Foo: Pass

b)

Class Foo(object): pass class Hoo(object): pass

c)

Class Foo: pass class Hoo (Foo): pass

d)

None of the others

10.

What would the following mean in a regular expression? $[a-z0-9]$

a)

Match any number of lowercase letters followed by any number of digits

b)

Match a lowercase letter or a digit

c)

Match an entire line as long as it is lowercase letters or digits

d)

Match any text that is surrounded by square braces

11.

What will the following Python code print out? python friends = ['Joseph', 'Glenn', 'Sally'] friends.sort() print(friends[0])

a)

Glenn

b)

Joseph

c)

Sally

d)

friends

12.

For the following list, how would you print out 'Sally'? python friends = ['Joseph', 'Glenn', 'Sally']

a)

print(friends[3])

b)

print(friends['Sally'])

c)

print(friends[2])

d)

print(friends[2:1])

13.

What does the following Python program print out? str1 = "Hello" str2 = "there" bob str1 str2 print(bob)

a)

Hello

b)

0

c)

Hellothere

d)

Hello There

14.

Which of the following will result in an error?

a)

print(str1[2])

b)

str1[1] = "x"

c)

print(str1[0:9])

d)

Both (b) and

15.

Which method can be used to remove any whitespace from both the beginning and the end of a string?

a)

Istrip()

b)

strip()

c)

rstrip()

d)

strim()

16.

What would the following Python code print out? python stuff = dict() print(stuff['candy'])

a)

-1

b)

0

c)

The program would fail with a traceback

d)

candy

17.

Which of these collections defines a DICTIONARY?

a)

("apple", "banana", "cherry")

b)

{"name": "apple", "color": "green"}

c)

{"apple", "banana", "cherry"}

d)

["apple", "banana", "cherry"]

18.

What is the output for: "Tutorials Point" [100:200]?

a)

Index error

b)

.

c)

'Tutorials Point'

d)

Syntax error

19.

Which of the following command is used to open a file "c:\temp.txt" in write-mode only?

a)

outfile = open("c:\temp.txt", "w")

b)

outfile = open("c:\temp.txt", "w")

c)

outfile = open( $file=$ "c:\temp.txt", "w+")

d)

outfile = open( $file=$ "c:\temp.txt", "w+")

20.

Given the file dog_breeds.txt, which of the following is the correct way to open the file for reading as a text file?

a)

open('dog_breeds.txt', 'wb')

b)

open('dog_breeds.txt', 'rb')

c)

open('dog_breeds.txt', 'r')

d)

open('dog_breeds.txt', 'w')

21.

Whenever possible, what is the recommended way to ensure that a file object is properly closed after usage?

a)

It doesn't matter

b)

By using the with statement

c)

By using the try/finally block

d)

Making sure that you use the close() method before the end of the script

22.

A list of lines is returned if using the method of

a)

readable()

b)

readlines()

c)

readline()

d)

read()

23.

If we open a file as follows: xfile = open('mbox.txt)

a)

for line in xfile:

b)

while (getline(xfile, line)) {

c)

READ xfile INTO LINE

d)

READ (xfile, *, $END=10)$ line

24.

When reading a file using the file object, what method is best for reading the entire file into a single string?

a)

readlines()

b)

readline()

c)

read_file_to_str()

d)

.read()

25.

Which operator can be used to compare two values?

a)

<>

b)

=

c)

>=

d)

==

26.

Which of the following statement about Python is not correct?

a)

The python ecosystem is very rich and provides easy to use tools for data science

b)

Due to its proprietary nature, database access from Python is not available for many databases

c)

There are libraries and APIs available to access many of the popular databases from Python

d)

Python is a popular scripting language for connecting and accessing databases

27.

What is the proper way to say "good-bye" to Python?

a)

quit()

b)

stop()

c)

exit()

d)

end()

28.

A USB memory stick is an example of which of the following components of computer architecture?

a)

Central Processing Unit

b)

Main Memory

c)

Secondary Memory

d)

None of these

29.

What is the most common Unicode encoding when moving data between systems?

a)

UTF-128

b)

UTF-8

c)

UTF-32

d)

UTF-64

30.

How would you express the constant floating-point value $3.2\times10^{3}$ in Python?

a)

3.2e-3

b)

3.2e3

c)

0.32

d)

32e-3

31.

You have the following dictionary definition: d={'foo': 100, 'bar': 200, 'baz': 300} What method call will delete the entry whose value is 200?

a)

d.pop("bar")

b)

d.remove("bar")

c)

d.remove("200")

d)

d.pop("200")

32.

Identify the data structure we use in the code given below: python # Code starts asthetic1 = 'quizOrbit asthetic2 = 'QuizOrbit print(asthetic1 = asthetic2) # Code ends

a)

HashMap

b)

Dictionary

c)

True

33.

Which of the following data structures in Python are immutable?

a)

Linked List

b)

Tree

c)

Tuple

d)

All of the above

34.

What is the output of the following code? python class Hum: def __init__(self, x = 1): self.x = x self.y = 1 def call(self, other_y): self.y = self.x + other_y print(self.x) p1 = Hum(2) p2 = Hum(4) p1.call(p2.x) print(p1.y)

a)

22

b)

46

c)

00

d)

11

35.

What does the Python help() function show when we pass an object into it as a parameter?

a)

It shows the parent class

b)

It shows the number of parameters to the constructor

c)

It shows the methods and attributes of the object

d)

It shows the type of the object

36.

What does the __init__() function do in Python?

a)

Initializes the class for use

b)

This function is called when a new object is instantiated.

c)

Initializes all the data attributes to zero when called

d)

None of the above

37.

For the following code: python x = 0 if x < 10: print("Below 10") if x < 20: print("Below 20") else: print("Something else") What is the output?

a)

x = 20

b)

This code will never print Something else regardless of the value for x.

c)

x = 20

d)

It will print out "Below 20"

38.

What is the purpose of the following Python code? python fhand = open('mbox-short.txt') x = 0 for line in fhand: x = x + 1 print(x)

a)

Remove the leading and trailing spaces from each line in mbox.txt

b)

Count the lines in the file mbox.txt

c)

Convert the lines in mbox.txt to upper case

d)

Reverse the order of the lines in mbox.txt

39.

What is the output of print(list[3]) if list = ['abcd', 786, 2.23, 'john', 70.2]

a)

['abcd', 786, 2.23]

b)

abcd

c)

[786, 2.23]

d)

None of the above.

40.

Once again consider this dictionary: d = {'foo': 100, 'bar': 200, 'baz': 300} What is the result of this statement: d['bar'] = d['foo']

a)

It raises an exception

b)

200, 300

c)

[200, 300]

d)

(200, 300)

41.

List a is defined as follows: l = [5, 6, 7] Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']

a)

l.extend(['d', 'e'])

b)

l.append(['d', 'e'])

c)

l += ['d', 'e']

d)

all of them are false

42.

Which of the following is not a Python reserved word?

a)

iterate

b)

continue

c)

else

d)

input

43.

In the following code, x = y. What is x?

a)

A variable

b)

A constant

c)

A parameter

d)

A pointer

44.

What is the value of the following expression? 4 + 2 * 10

a)

44

b)

24

c)

25

d)

4.2

45.

Which of the following elements of a mathematical expression in Python is evaluated first?

a)

Addition +

b)

Multiplication *

c)

Subtraction -

d)

Parentheses ()

46.

How do you create a variable x with the numeric value 5?

a)

x == 5

b)

x.value = 5

c)

Both the answers A and B are correct

d)

Both the answers A and B are incorrect

47.

What is the correct syntax to output the type of a variable or object in Python?

a)

print(type(x))

b)

print(type of x)

c)

print type(x)

d)

print(type(x))

48.

When you have multiple lines in an if block, how do you indicate the end of the if block?

a)

You omit the semicolon ; on the last line of the if block

b)

You de-indent the next line past the if block to the same level of indent as the original if statement

c)

You put the colon : character on a line by itself to indicate we are done with the if block

d)

You use a curly brace { } after the last line of the if block

49.

You look at the following text if x == 0: print('Still') print('All done') It looks perfect but Python is giving you an 'IndentationError: on the second print statement. What is the most likely reason?

a)

In order to make humans feel inadequate, Python randomly emits 'Indentation Errors' on perfectly good code - after about an hour the error will just go away without any changes to your program.

b)

Python has reached its limit on the largest Python program that can be run

c)

Python thinks 'Still' is a mis-spelled word in the string

d)

You have mixed tabs and spaces in the file

50.

What will the following code print? python x = 6 if x < 10: print('Small') elif x < 10: print('Medium') else: print('LARGE') print('All done')

a)

LARGE All done

b)

Small

c)

Small All done

d)

Small Medium LARGE All done

51.

What is the iteration variable in the following Python code? for letter in 'banana': print(letter)

a)

banana

b)

for

c)

letter

d)

print

52.

If a class is derived from two different classes, it's called ___________.

a)

Multilevel Inheritance

b)

Multiple Inheritance

c)

Hierarchical Inheritance

d)

Hybrid Inheritance

53.

Given the code: class People(): def __init__(self, name): self.name = name def namePrint(self): print(self.name) person1 = People("Sally") person2 = People("Louise") person1.namePrint() What is the correct answer?

a)

person1 and person2 are two different instances of the People class

b)

The init method is used to set initial values for attributes

c)

self is not used in def namePrint(self)

d)

person2 has a different value for 'name' than person1

54.

Given the code: class People(): def __init__(self, name): self.name = name def namePrint(self): print(self.name) person1 = People("Sally") person2 = People("Louise") person1.namePrint() What is the correct output?

a)

Sally

b)

Louise

c)

Sally Louise

d)

person1

55.

What's the output of the following code snippet? class Dog: def walk(self): return "walking" def speak(self): return "Woof!" class JackRussellTerrier(Dog): def speak(self): return "Arff!" bobo = JackRussellTerrier() bobo.walk()

a)

Arff

b)

walking

c)

AttributeError: 'JackRussellTerrier' object has no attribute 'walk'

d)

Woof!

56.

Object and class attributes are accessed using ___________ notation in Python:

a)

Dot notation.

b)

Arrow notation.

c)

Plus notation.

d)

And notation.

57.

The _______ keyword defines a template indicating the data that will be in an object of the class and the functions that can be called on an object of the class

a)

Class

b)

object

c)

class

d)

instance

58.

Given the code: class Pokemon(): def __init__(self, name, type): self.name = name self.type = type def stringPokemon(self): print("Pokemon name is {self.name} and type is {self.type}") class GrassType(Pokemon): def stringPokemon(self): print("Grass type pokemon name is {self.name}") poke1 = GrassType("Bulbasaur", "Grass") poke1.stringPokemon() poke2 = Pokemon("Charizard", "Fire") poke2.stringPokemon() What is the correct output?

a)

Grass type pokemon name is Bulbasaur Pokemon name is Charizard and type is Fire

b)

Pokemon name is Bulbasaur and type is Grass Pokemon name is Charizard and type is Fire

c)

Grass type pokemon name is Bulbasaur Grass type pokemon name is Charizard

d)

Error because the extending class has a stringPokemon() function which already exists.

59.

Which of the following statements is true?

a)

A class is a blueprint for the object

b)

You can only make a single object from the given class

c)

Both statements are true

d)

Neither statement is true

60.

What is 'self' typically used for in a Python method within a class?

a)

To terminate a loop

b)

To set the residual value in an expression where the method is used

c)

The number of parameters to the method

d)

To refer to the instance in which the method is being called

61.

Which method can be used to replace parts of a string?

a)

replace()

b)

replaceString()

c)

repl()

d)

repl()

62.

Which method can be used to return a string in upper case letters?

a)

toLower()

b)

.lower()

c)

lowercase()

d)

lowerCase()

63.

How would you use the index operator to print out the letter q from the following string? X = "From marquard@uct.ac.za"

a)

print(X[q])

b)

print(X[10])

c)

print(X[9])

d)

print(X[8])

64.

What is a correct syntax to output "Hello World" in Python?

a)

echo "Hello World"

b)

p("Hello World")

c)

print("Hello World")

d)

echo("Hello World")

65.

(1) ast = "Hello Bob (2) ast = ast() (3) ast (4) ast = ast.upper() (5) print('First' ast) (6) ast = ast() (7) print('Second' ast) In the following code (numbers added) - which will be the last line to execute successfully?

a)

1

b)

2

c)

5

d)

6

66.

Which data structure is the output of the code given below? # Code starts col = (2,4,6), (5,7,9) finalAns = list(col) print(type(finalAns)) # Code Ends

a)

Tree

b)

List

c)

Set

d)

Dictionary

67.

What does the following Python code print out? a = [1, 2, 3] b = [4, 5, 6] c = a + b print(c)

a)

21

b)

[1, 2, 3, 4, 5, 6]

c)

If it raises an exception

d)

0

68.

Which collection does not allow duplicate members?

a)

SET

b)

DICTIONARY

c)

TUPLE

d)

LIST

69.

What does the following Python code do? fhand = open('mbox-short.txt') inp = fhand.read()

a)

Checks to see if the file exists and can be written

b)

Turns the text in the file into a graphic image like a PNG or JPG

c)

Reads the entire file into the variable inp as a string

d)

Prompts the user for a file name

70.

The following code sequence fails with a traceback when the user enters a file that does not exist. How would you avoid the traceback and make it so you could print out your own error message when a bad file name was entered? fname = raw_input('Enter the file name: ') try: fhand = open(fname) except: print('Bad file name:', fname) exit()

a)

try / except

b)

signal handlers

c)

try/catch/finally

d)

on error resume next

71.

What do we use the second parameter of the open() call to indicate

a)

How large we expect the file to be

b)

The list of folders to be searched to find the file we want to open

c)

Whether we want to read data from the file or write data to the file

d)

What disk drive the file is stored on

72.

What is the purpose of the newline character in text files?

a)

It adds a new network connection to retrieve files from the network

b)

It indicates the end of one line of text and the beginning of another line of text

c)

It enables random movement throughout the file

d)

It allows us to open more than one files and read them in a synchronized manner

73.

How do you insert something on a new line in a file?

a)

write newline(x)

b)

\n

c)

You cannot do this

d)

type the content on the line below

74.

If you write a Python program to read a text file and you see extra blank lines in the output that are not present in the file input as shown below, what Python string function will likely solve the problem? From: stephen.marquard@uct.ac.za From: louis@media.berkeley.edu From: zqian@umich.edu From: rjlowe@iupui.edu

a)

find()

b)

startswith()

c)

rstrip()

d)

split()

75.

What is the name of this symbol -> ?

a)

Chevrons

b)

Hash tags

c)

Colon

d)

Semi-Colon

76.

Which of the parts of a computer actually executes the program 'instructions'?

a)

RAM

b)

CPU

c)

Input Output Devices

d)

Secondary Memory

77.

What extension must you add to the end of a file when saving?

a)

.py

b)

.txt

c)

.pyth

d)

.txt

78.

What is the best way to think about a 'Syntax Error' while programming?

a)

The computer needs to have its software upgraded

b)

The computer is overheating and just wants you to stop to let it cool down

c)

The computer has used GPS to find your location and hates everyone from your town

d)

The computer did not understand the statement that you entered

79.

What are the names of the two types of mode that are used in Python?

a)

Interactive mode & Script mode

b)

Interactive mode & Scratch mode

c)

Interactive mode & Imperial mode

d)

Imperial mode & Script mode

80.

Which of the following statements assigns the value 100 to the variable x in Python

a)

x == 100

b)

let x = 100

c)

x <- 100

d)

x = 100

e)

x = 100

81.

What is the output of the following python code snippet? emp1 = ('Ajay', 25, 100000) emp2 = ('Nithe', 21, 120000) emp1[2] = 20000 print(emp1[2] + emp2[2]) # Code Ends

a)

55000

b)

25000

c)

Type Error

d)

None of the above.

82.

What does the following Python code print out? a = [1, 2, 3] b = [4, 5, 6] c = a - b print(c)

a)

21

b)

[1, 2, 3, 4, 5, 6]

c)

If it raises an exception

d)

0

83.

Find the output of the code given below? # Code starts x = [21, 25, 37, 94] x.append(75, 62, 79) print(len(x)) # Code Ends

a)

1

b)

4

c)

7

d)

Error

84.

What is the correct way to create a function in Python?

a)

def function[]:

b)

define function(){ }

c)

function() { }

d)

create function()

e)

def function():

85.

In Python, a function within a class definition is called a?

a)

an operation

b)

a method

c)

a callable

d)

a class function

e)

a factory

86.

For the following code, which of the following statements is true? def PrintHello(): print("Hello") x = PrintHello()

a)

Both PrintHello() and x refer to the same object

b)

PrintHello() and x refer to different objects

c)

Syntax error! You cannot assign function to a variable in Python

87.

Find the output of the given Python program. a = 10 if a <= 15: print("Hi") else: print("Know Program!")

a)

Hi

b)

Hello

c)

Hi Hello

d)

Hi Know Program

88.

Which of the following reserved keyword is used to end a function, return generator?

a)

break

b)

switch

c)

Return

d)

yield

89.

What is the result of the following statement list([x for x in range(3, 6)])

a)

[3, 4, 5]

b)

3, def

c)

[100, 101, 102]

d)

It causes an exception

90.

Which data structure is being put to use in the code given below? # Code starts org = 'QuizOrbit' count = {} for i in org: if i in count: count[i]+=1 else: count[i]=1 print(count) # Code Ends

a)

String

b)

List

c)

Tuple

d)

Dictionary

91.

Which of these collections defines a LIST?

a)

{"name": "apple", "color": "green"}

b)

["apple", "banana", "cherry"]

c)

{"apple", "banana", "cherry"}

d)

("apple", "banana", "cherry")

92.

If you want to transform a list of strings, say ['a','b','c'] into a single string with a comma between each item, which of the following would you give as the input to join()?

a)

,

b)

string

c)

input_list

d)

str

93.

ng would you give as the input to join()?

a)

,

b)

string

c)

input_list

d)

str

94.

What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true?

a)

Un-indent the all of the conditional code

b)

Indent the line below the if statement

c)

Start the statement with a '>' character

d)

Begin the statement with a curly brace { }

95.

What will be the value of x after the following statement executes? x = 1 * 2 - 3 / 4 % 2

a)

1

b)

2

c)

4

d)

6

96.

Assume x and y are assigned as follows: x = 3; y = 5; What is the effect of this statement? x, y = y, x

a)

The values of x and y are unchanged

b)

Both x and y are 5

c)

Both x and y are 2

d)

The values of x and y are swapped

97.

Which of the following Python statements would print out the length of a list stored in the variable data?

a)

print(length(data))

b)

print(data.length())

c)

print(len(data))

d)

print(data.length)

98.

What will be the value of x after the following statement executes? x = 1 + 2 * 3 - 8 / 4

a)

3.0

b)

4.5

c)

4

d)

5.0

99.

Which statement is used to stop a loop?

a)

exit

b)

break

c)

stop

d)

return

100.

How do you start writing an if statement in Python?

a)

if x < y

b)

if (x > y)

c)

if x > y then:

d)

if x > y

101.

What is true about the following code segment if x == 5: print('First') print('Second') print('Third')

a)

Depending on the value of x, either all three of the print statements will execute or none of the statements will execute

b)

The string 'First' will always print out regardless of the value for x.

c)

The string 'Is 5' will never print out regardless of the value for x.

d)

Only two of the three print statements will print out if the value of x is less than zero.

102.

True or False? In order to extend a class, the new class should have access to all the data and inner workings of the parent class

a)

True

b)

False

103.

What is the last action that must be performed on a file?

a)

Close

b)

Save

c)

End

d)

Write

104.

Which of these operators is not a 'comparison / logical operator'?

a)

==

b)

=

c)

<=

d)

>=

105.

In the following code: print(98.6). What is '98.6'?

a)

A variable

b)

A constant

c)

A parameter

d)

A pointer

106.

What does the following Python sequence print out? x = 'From: Using the character' print(x[1])

a)

F

b)

From: Using the ]

c)

[From:]

d)

From:

107.

Which of the following is NOT a good synonym for 'class' in Python?

a)

direction

b)

blueprint

c)

pattern

d)

template

108.

Which of the following statements is not true about object-oriented programming?

a)

One of the benefits of object-oriented programming is that it can hide complexity.

b)

A class contains functions as well as the data that is used by those functions.

c)

Constructor methods are required to initialize an object and destructor methods are required to destroy the object when no longer required.

d)

A powerful feature of object-oriented programming is the ability to create a new class by extending an existing class.

109.

Which of the following would separate a string 'input_string' on the first 2 occurrences of the letter 'a'?

a)

e.split('input_string', 2)

b)

e.split('input_string', 'a', 2)

c)

e.split('input_string', 'a', maxsplit=2)

d)

input_string.split('a', maxsplit=2)

110.

List a is defined as follows: a = [1, 2, 3, 4] Select all of the following statements that remove the middle element 3 from a so that a equals [1, 2, 4]

a)

a[2:2] = []

b)

a[2] = []

c)

del a[2]

d)

a.remove(3)

111.

How would you express the constant floating-point value $3.2\times10^3$ in Python?

a)

3.2e-3

b)

3.2e3

c)

0.32

d)

32e-3

112.

For the following code, which of the following statements is true? def PrintHello(): print('Hello') x = PrintHello()

a)

PrintHello() is a function and x is a variable. None of them are objects

b)

Both PrintHello() and x refer to the same object

c)

PrintHello() and x refer to different objects.

d)

Syntax error! You cannot assign function to a variable in Python.

113.

Which of these words is a reserved word in Python?

a)

while

b)

payroll

c)

names

d)

pizza

114.

What Python function would you use if you wanted to prompt the user for a file name to open?

a)

file_input()

b)

read()

c)

input()

d)

open()

115.

_______ is not a keyword, but by convention it is used to refer to the current instance (object) of a class.

a)

class

b)

def

c)

'self'

d)

'init'

116.

Which of the following does not correctly create an object instance?

a)

puppy: Dog('Tame')

b)

dog = Dog('Jamie')

c)

jamie = Dog()

d)

puppy = new Dog('Tame')

117.

What is the type of the return value of the re.findall() method?

a)

A list of strings

b)

An integer

c)

A boolean

d)

A single character

118.

Which of the following is a comment in Python?

a)

// This is a test

b)

/* This is a test */

c)

# This is a test

d)

& This is a test

119.

What will the following Python code print out? friends = ['Joseph', 'Glenn', 'Sally'] friends.sort() print(friends[0])

a)

Glenn

b)

Joseph

c)

Sally

d)

Friends

120.

What is the syntax to look up the fullname attribute in an object stored in the variable colleen?

a)

colleen : fullname

b)

colleen . fullname

c)

colleen.fullname

d)

colleen['fullname']

121.

What is the result of this statement? print(ord('foo'))

a)

102

b)

It raises an exception

c)

102, 111, 111

d)

324

122.

class People(): def __init__(self, name): self.name = name def namePrint(self): print(self.name) person1 = People("Sally") person2 = People("Louise") person1.namePrint()

a)

Sally

b)

Louise

c)

Sally Louise

d)

person1

123.

What would the following Python code print out? fruit = "Banana" fruit[0] = 'b' print(fruit)

a)

Nothing would print - the program fails with a traceback error

b)

B

c)

b

d)

banana

124.

What is the output of the following code? class Point: def __init__(self, x=0, y=0): self.x = x self.y = y p1 = Point() print(p1.x, p1.y)

a)

Initializes the class for use

b)

0 0

c)

1 1

d)

None None

e)

X y

125.

What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is False?

a)

break

b)

switch

c)

else

d)

toggle

126.

What is the most common Unicode encoding when moving data between systems?

a)

UTF-128

b)

UTF-8

c)

UTF-32

d)

UTF-64

127.

Which one is NOT a legal variable name?

a)

myvar

b)

Myvar

c)

My_var

d)

My-var

128.

Which of the following can be used to invoke the _init_ method in B from A, where A is a subclass of B?

a)

super().__init__()

b)

super()._init_self()

c)

B.init()

129.

Which method can be used to return a string in upper case letters?

a)

upper()

b)

uppercase()

c)

toUpperCase()

d)

upperCase()

130.

What does the following code print out? print("123" + "abc")

a)

123abc

b)

123+abc

c)

This is a syntax error because you cannot add strings

d)

hello world

131.

What will the following program print out? x = 15 x = x + 10 print(x)

a)

25

b)

5

c)

15

d)

"print x"

132.

Python scripts' files have names that end with:

a)

.pyc

b)

.py

c)

.exe

d)

.doc

133.

For the following list, how would you print out 'Sally'? friends = ['Joseph', 'Glenn', 'Sally']

a)

print(friends['Sally'])

b)

print(friends[2:1])

c)

print(friends[2])

d)

print(friends[3])