Q: 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)
Solution: self.o1 was never created.
Q: 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)
Solution: Id in this case will be the attribute of the class.
Q: What will be the output of the following Python code? >>>example = "snow world" >>>print("%s" % example[4:7])
Solution: Execute in the shell and verify.
Q: What will be the output of the following Python code? >>>max("what are you")
Solution: Max returns the character with the highest ascii value.
Q: Given a string example=”hello” what is the output of example.count(‘l’)?
Solution: l occurs twice in hello.
Q: What will be the output of the following Python code? >>>example = "helle" >>>example.find("e")
Solution: Returns lowest index.
Q: What will be the output of the following Python code? >>>example = "helle" >>>example.rfind("e")
Solution: Returns highest index.
Q: What will be the output of the following Python code? >>>example="helloworld" >>>example[::-1].startswith("d")
Solution: Starts with checks if the given string starts with the parameter that is passed.
Q: To concatenate two strings to a third what statements are applicable?
Solution: __add__ is another method that can be used for concatenation.
You Have Score    | /9 |