0% found this document useful (0 votes)
225 views25 pages

Python-Institute Onlinetest PCAP v2021-04-27 by Lucas 40q

This document contains a summary of a Python certification practice exam with 27 multiple choice questions covering various Python topics such as operators, loops, functions, classes, files and streams. The questions test knowledge of basic Python syntax and semantics.

Uploaded by

eserranos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views25 pages

Python-Institute Onlinetest PCAP v2021-04-27 by Lucas 40q

This document contains a summary of a Python certification practice exam with 27 multiple choice questions covering various Python topics such as operators, loops, functions, classes, files and streams. The questions test knowledge of basic Python syntax and semantics.

Uploaded by

eserranos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

PCAP

Number: PCAP
Passing Score: 800
Time Limit: 120 min
File Version: 1

PCAP

https://www.gratisexam.com/

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Exam A

QUESTION 1
And operator able to perform bitwise shifts is coded as (Select two answers)

https://www.gratisexam.com/

A. --
B. ++
C. <<
D. >>

Correct Answer: CD
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.geeksforgeeks.org/basic-operators-python/

QUESTION 2
What will the value of the i variable be when the following loop finishes its execution?

A. 10
B. the variable becomes unavailable
C. 11
D. 9

Correct Answer: B

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.programiz.com/python-programming/pass-statement

QUESTION 3
The following expression

is:

A. equal to 1
B. invalid
C. equal to 2
D. equal to -1

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 4
What is the output of the following piece of code?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. ant’ bat’ camel
B. ant”bat” camel
C. antbatcamel
D. print (a, b, c, sep= ‘ ” ’)

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 5
What is the expected output of the following snippet?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. the code is erroneous
B. 3
C. 7
D. 15

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 6
How many lines does the following snippet output?

A. three
B. one
C. two
D. four

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 7
Which of the following literals reflect the value given as 34.23? (Select two answers)

A. .3423e2
B. 3423e-2
C. .3423e-2
D. 3423e2

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 8
Assuming that the following snippet has been successfully executed, which of the equations are True? (Select two answers)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. len(a) == len (b)
B. b [0] +1 ==a [0]
C. a [0] == b [0]
D. a [0] + 1 ==b [0]

Correct Answer: AC
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 9
Assuming that the following snippet has been successfully executed, which of the equations are False? (Select two answers)

A. len(a)== len (b)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. a [0]-1 ==b [0]
C. a [0]== b [0]
D. b [0] - 1 ==a [0]

Correct Answer: AB
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 10
Which of the following statements are true? (Select two answers)

A. Python strings are actually lists


B. Python strings can be concatenated
C. Python strings can be sliced like lists
D. Python strings are mutable

Correct Answer: BC
Section: (none)
Explanation

Explanation/Reference:
Reference: https://docs.python.org/2/tutorial/introduction.html

QUESTION 11

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the expected output of the following snippet?

A. 1
B. 4
C. 2
D. 3

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 12
What is the expected output of the following snippet?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. abc
B. The code will cause a runtime exception
C. ABC
D. 123

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 13
How many elements will the list2 list contain after execution of the following snippet?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. zero
B. five
C. seven
D. three

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 14
What would you used instead of XXX if you want to check weather a certain ‘key’ exists in a dictionary called dict? (Select two answers)

A. ‘key’ in dict
B. dict [‘key’] != None
C. dict.exists (‘key’)
D. ‘key’ in dict.keys ( )

Correct Answer: BD
Section: (none)
Explanation

Explanation/Reference:
Reference: https://thispointer.com/python-how-to-check-if-a-key-exists-in-dictionary/

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 15
What is the expected behavior of the following snippet?

It will:

A. cause a runtime exception


B. print 1
C. print 0, [1]
D. print [1]

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 16
What can you do if you don’t like a long package path like this one?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. you can make an alias for the name using the alias keyword
B. nothing, you need to come to terms with it
C. you can shorten it to alpha . zeta and Python will find the proper connection
D. you can make an alias for the name using the as keyword

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Reference: https://stackoverflow.com/questions/706595/can-you-define-aliases-for-imported-modules-in-python

QUESTION 17
Is it possible to safely check if a class/object has a certain attribute?

A. yes, by using the hasattr attribute


B. yes, by using the hasattr ( ) method
C. yes, by using the hassattr ( ) function
D. no, it is not possible

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Reference: https://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python

QUESTION 18
There is a stream named s open for writing. What option will you select to write a line to the stream?

A. s. write (“Hello\n”)
B. write (s, “Hello”)
C. s.writeln (“Hello”)
D. s. writeline (“Hello”)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Reference: https://en.wikibooks.org/wiki/Python_Programming/Input_and_Output

QUESTION 19
You are going to read just one character from a stream called s. Which statement would you use?

A. ch = read (s, 1)
B. ch= s.input (1)
C. ch= input (s, 1)
D. ch= s.read (1)

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Reference: https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user

QUESTION 20
What can you deduce from the following statement? (Select two answers)

A. str is a string read in from the file named file.txt


B. a newline character translation will be performed during the reads
C. if file. txt does not exist, it will be created
D. the opened file cannot be written with the use of the str variable

Correct Answer: AD
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 21
The following class hierarchy is given. What is the expected out of the code?

A. BB
B. CC
C. AA
D. BC

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 22
Python’s built in function named open () tries to open a file and returns:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. an integer value identifying an opened file
B. an error code (0 means success)
C. a stream object
D. always None

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 23
Which of the following words can be used as a variable name? (Select two valid names)

A. for
B. True
C. true
D. For

Correct Answer: CD
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.pluralsight.com/guides/python-basics-variables-assignment

QUESTION 24
A keyword (Select two answers)

A. can be used as an identifier


B. is defined by Python’s lexis
C. is also known as a reserved word
D. cannot be used in the user’s code

Correct Answer: BC
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:
Reference: https://www.programiz.com/python-programming/keywords-identifier

QUESTION 25
How many stars (*) does the snippet print?

A. the code is erroneous


B. five
C. four
D. two

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 26
Assuming that the V variable holds an integer value to 2, which of the following operators should be used instead of OPER to make the expression equal to 1?

V OPER 1

A. <<<
B. >>>
C. >>
D. <<

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 27
How many stars (*) does the following snippet print?

A. the code is erroneous


B. five
C. three
D. four

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 28
Which of the listed actions can be applied to the following tuple? (Select two answers)

A. tup [:]
B. tup.append (0)
C. tup [0]
D. del tup

Correct Answer: AD
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 29
Which of the equations are True? (Select two answers)

A. chr (ord (x)) = = x


B. ord (ord (x)) = = x
C. chr (chr (x)) = = x
D. ord (chr (x)) = = x

Correct Answer: AD
Section: (none)
Explanation

Explanation/Reference:

QUESTION 30
If you want to transform a string into a list of words, what invocation would you use? (Select two answers)

Expected output:

Code:

A. s.split ()
B. split (s, ‘ ‘)
C. s.split (‘ ‘)
D. split (s)

Correct Answer: AC
Section: (none)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation

Explanation/Reference:

QUESTION 31
Assuming that 1st is a four-element list is there any difference between these two statements?

A. yes, there is, the first line empties the list, the second line deletes the list as a whole
B. yes, there is, the first line deletes the list as a whole, the second line just empties the list
C. no, there is no difference
D. yes, there is, the first line deletes the list as a whole, the second line removes all the elements except the first one

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 32
Package source directories/folders can be:

A. converted into the so-called pypck format


B. packed as a ZIP file and distributed as one file
C. rebuilt to a flat form and distributed as one directory/folder
D. removed as Python compiles them into an internal portable format

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 33

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A two-parameter lambda function raising its first parameter to the power of the second parameter should be declared as:

A. lambda (x, y) = x ** y
B. lambda (x, y): x ** y
C. def lambda (x, y): return x ** y
D. lambda x, y: x ** y

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 34
A method for passing the arguments used by the following snippet is called:

A. sequential
B. named
C. positional
D. keyword

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 35
What is the expected behavior of the following code?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
It will:

A. print 0
B. cause a runtime exception
C. prints 3
D. print an empty line

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 36
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:

A. except Ex1 Ex2:


B. except (ex1, Ex2):
C. except Ex1, Ex2:
D. except Ex1+Ex2:

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.programiz.com/python-programming/exception-handling

QUESTION 37
A function called issubclass (c1, c2) is able to check if:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. c1 and c2 are both subclasses of the same superclass
B. c2 is a subclass of c1
C. c1 is a subclass of c2
D. c1 and c2 are not subclasses of the same superclass

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.oreilly.com/library/view/python-in-a/9781491913833/ch04.html

QUESTION 38
A class constructor (Select two answers)

A. can return a value


B. cannot be invoked directly from inside the class
C. can be invoked directly from any of the subclasses
D. can be invoked directly from any of the superclasses

Correct Answer: BC
Section: (none)
Explanation

Explanation/Reference:

QUESTION 39
You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Select two answers)

A. data = bytearray (16)


bf.readinto (data)
B. data = binfile.read (bytearray (16))
C. bf. readinto (data = bytearray (16))
D. data = bytearray (binfile.read (16))

Correct Answer: CD
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:
Reference: https://www.devdungeon.com/content/working-binary-data-python

QUESTION 40
What is the expected output of the following snippet?

A. True False
B. True True
C. False False
D. False True

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2

You might also like