What will be the output of the following Python code?
a) Peter Pan b) John Pan c) Peter Smith d) John Smith Answer: b) John Pan Explanation: In the constructor, firstname, mi, and lastname of the object are assigned as John, F, and Smith respectively.
To read the entire remaining contents of the file as a string from a file object infile, we use _
a) infile.read(2) b) infile.read() c) infile.readline() d) infile.readlines() Answer: b) infile.read() Explanation: The read function is used to read all the lines in a file. read() will read in the entire file as a single
To concatenate two strings to a third, what statements are applicable?
a) s3 = s1 . s2 b) s3 = s1.add(s2) c) s3 = s1.__add__(s2) d) s3 = s1 * s2 Answer: c) s3 = s1.__add__(s2) Explanation: The __add__() method in Python specifies what happens when
How are required arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value b) identifier followed by the default value within backticks (“) c) identifier followed by the default value within square brackets () d) identifier
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
(a) Error (b) None (c) 25 (d) 2Read Answer: (c) 25 Explanation: -1 corresponds to the last index in the list. That’s why 25 is the right answer!
Can one block of except statements handle multiple exceptions?
a) yes, except TypeError, SyntaxError [,…] b) yes, like except [TypeError, SyntaxError] c) no d) none of the mentioned Answer: a) yes, except TypeError, SyntaxError [,…] Explanation: Each type of exception can be specified directly.
CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS
My students are the presents from God to me
Do you want to learn
Hey, I’m Aniket. I’m determined to make you one of the best developers in the history of Information technology.
My only question is, are you ready?