219). What will be the output of the following Python code?
class father:
def __init__(self, param):
self.o1 = param
class child(father):
def __init__(self, param):
self.o2 = param
>>>obj = child(22)
>>>print "%d %d" % (obj.o1, obj.o2)
[A]None None
[B]None 22
[C]22 None
[D]Error is generated
Show Answer
Correct Answer: Error is generated
Notes:
Answer: d
Explanation: self.o1 was never created.
220). What will be the output of the following Python code?
class tester:
def __init__(self, id):
self.id = str(id)
id="224"
>>>temp = tester(12)
>>>print(temp.id)
[A]224
[B]Error
[C]12
[D]None
Show Answer
Correct Answer: 12
Notes:
Answer: c
Explanation: Id in this case will be the attribute of the class.
221). What will be the output of the following Python code?
>>>example = "snow world"
>>>print("%s" % example[4:7])
[A]wo
[B]world
[C]sn
[D]rl
Show Answer
Correct Answer: wo
Notes:
Answer: a
Explanation: Execute in the shell and verify.
222). What will be the output of the following Python code?
>>>example = "snow world"
>>>example[3] = 's'
>>>print example
[A]snow
[B]snow world
[C]Error
[D]snos world
Show Answer
Correct Answer: Error
Notes:
Answer: c
Explanation: Strings cannot be modified.
223). What will be the output of the following Python code?
>>>max("what are you")
Show Answer
Correct Answer: y
Notes:
Answer: d
Explanation: Max returns the character with the highest ascii value.
224). Given a string example=”hello” what is the output of example.count(‘l’)?
>>>max("what are you")
Show Answer
Correct Answer: 2
Notes:
Answer: a
Explanation: l occurs twice in hello.
225). What will be the output of the following Python code?
>>>example = "helle"
>>>example.find("e")
Show Answer
Correct Answer: 1
Notes:
Answer: c
Explanation: Returns lowest index.
226). What will be the output of the following Python code?
>>>example = "helle"
>>>example.rfind("e")
Show Answer
Correct Answer: 4
Notes:
Answer: b
Explanation: Returns highest index.
227). What will be the output of the following Python code?
>>>example="helloworld"
>>>example[::-1].startswith("d")
[A]dlrowolleh
[B]True
[C]-1
[D]None
Show Answer
Correct Answer: True
Notes:
Answer: b
Explanation: Starts with checks if the given string starts with the parameter that is passed.
228). To concatenate two strings to a third what statements are applicable?
>>>example="helloworld"
>>>example[::-1].startswith("d")
[A]s3 = s1 . s2
[B]s3 = s1.add(s2)
[C]s3 = s1.__add__(s2)
[D]s3 = s1 * s2
Show Answer
Correct Answer: s3 = s1.__add__(s2)
Notes:
Answer: c
Explanation: __add__ is another method that can be used for concatenation.