PCAP : Certified Associate in Python Programming : Part 05
-
What is the expected behavior of the following code?
- it outputs 3
- the code is erroneous and it will not execute
- it outputs 1
- it outputs 2
Explanation:
-
Which of the following snippets will execute without raising any unhandled exceptions? (Choose two.)
Explanation:
-
What is the expected behavior of the following code?
- it outputs
error
- it outputs
<class ‘IndexError’>
- it outputs list assignment index out of range
- the code is erroneous and it will not execute
Explanation:
- it outputs
-
What is true about the following snippet? (Choose two.)
- the string
it’s nice to see you
will be seen - the string
I feel fine
will be seen - the code will raise an unhandled exception
- the string
what a pity
will be seen
Explanation:
- the string
-
Which of the following expressions evaluate to True? (Choose two.)
-
ord(“Z”) - ord(“z”) == ord(“0”)
-
chr(ord(‘A’) +1) == ‘B’
-
len(‘\’’) == 1
-
len(“““ ”””) == 0
-
-
Which of the following invocations are valid? (Choose two.)
-
“python”.sort()
-
sorted(“python”)
-
rfind(“python”,“r”)
-
“python”.index(“th”)
-
-
What is the expected behavior of the following code?
- it raises an exception
- it outputs 0
- it outputs 3
- it outputs ‘None’
Explanation:
-
Which of the following statements are true? (Choose two.)
- II in ACII stands for Information Interchange
- a code point is a number assigned to a given character
- ACII is synonymous with UTF-8
- \e is an escape sequence used to mark the end of lines
Explanation:Reference: https://www.tutorialsteacher.com/python/ascii-method -
Which of the following expressions evaluate to True? (Choose two.)
str(1-1)
in‘123456789’[:2]
‘dcb’
not in‘abcde’[::-1]
‘phd’
in‘aplpha’
‘True
’ not in ‘False’
-
What is the expected behavior of the following code?
- it raises an exception
- it outputs True
- it outputs False
- it outputs nothing
Explanation:
-
Which of the following expressions evaluate to True? (Choose two.)
-
121 + 1 != ‘1’ + 2 * ‘2’
-
‘1’ + ‘1’ + ‘1’ < ‘1’ *3’
-
‘AbC’.lower() < ‘AB’
-
‘3.14’ != str(3.1415)
-
-
Assuming that the snippet below has been executed successfully, which of the following expressions evaluate to True? (Choose two.)
string = ‘python’[::2]
string = string[-1] + string[-2]
- string[0] == ‘o’
- string is None
- len(string) == 3
- string[0] == string [-1]
-
What is the expected behavior of the following code?
- it outputs 0
- it outputs 1
- it raises an exception
- it outputs 2
Explanation:
-
Assuming that the following inheritance set is in force, which of the following classes are declared properly? (Choose two.)
- class Class_4(D,A): pass
- class Class_3(A,C): pass
- class Class_2(B,D): pass
- class Class_1(C,D): pass
-
What is the expected output of the following snippet?
- True upper
- True lower
- False upper
- False lower
Explanation:
-
Assuming that the code below has been placed inside a file named code.py and executed successfully, which of the following expressions evaluate to True? (Choose two.)
-
len(ClassB.__bases__) ==2
-
ClassA.__module__ == ‘__main__’
-
__name__ == ‘code.py’
-
str(Object) == ‘Object’
-
-
What is the expected behavior of the following code?
- it outputs 1
- it outputs 3
- it outputs 6
- it raises an exception
Explanation:
-
What is the expected behavior of the following code?
- it outputs 0
- it raises an exception
- it outputs 1
- it outputs 2
Explanation:
-
What is true about Object-Oriented Programming in Python? (Choose two.)
- each object of the same class can have a different set of methods
- a subclass is usually more specialized than its superclass
- if a real-life object can be described with a set of adjectives, they may reflect a Python object method
- the same class can be used many times to build a number of objects
Explanation:Reference: https://www.whitman.edu/mathematics/java_tutorial/java/javaOO/subclasses.html -
What is true about Python class constructors? (Choose two.)
- there can be more than one constructor in a Python class
- the constructor must return a value other than None
- the constructor is a method named __init__
- the constructor must have at least one parameter
Subscribe
0 Comments
Newest