Instruction
- Total number of questions : 2
- Time allotted : 03:00 Minutes:Seconds.
- Each question carry 1 mark, no negative marks.
- DO NOT refresh the page.
- All the best
Computer Programming [ Question No: 1 To 2 ] :
Which of the given options best describes the truthfulness of the following statements?
i) A tuple is a sequence of immutable Python objects, in the given tuple course = "l", "m", "n", "o", has four elements.
ii) To explicitly remove an entire tuple, use the drop statement.
What is the expected output of the following Python code?
print("\nDictionary Iteration")
d = dict()
d['lmn'] = 123
d['abc'] = 345
for i in d :
print("%s %d" %(i, d[i]))
Total number of questions : 2
Number of answered questions : 0
Number of unanswered questions : 2
Computer Programming [ Question No: 1 To 2 ] :
Which of the given options best describes the truthfulness of the following statements?
i) A tuple is a sequence of immutable Python objects, in the given tuple course = "l", "m", "n", "o", has four elements.
ii) To explicitly remove an entire tuple, use the drop statement.
Your Answer : (Not Answered)
Correct Answer : C
Statement i is true and statement ii is false. A tuple is a sequence of immutable Python objects, and the tuple course with "l", "m", "n" and "o" has four elements. To remove an entire tuple explicitly, Python uses the del statement, and there is no drop statement for this, so statement ii is false. So the third option is correct. Items can still be removed from a tuple only by building a new one, because a tuple cannot be changed after it is made.
What is the expected output of the following Python code?
print("\nDictionary Iteration")
d = dict()
d['lmn'] = 123
d['abc'] = 345
for i in d :
print("%s %d" %(i, d[i]))
Your Answer : (Not Answered)
Correct Answer : A
The output is a blank line, then 'Dictionary Iteration', then 'lmn 123' and 'abc 345'. The string begins with \n, which prints an empty line first. The dictionary d keeps the keys in the order inserted (in current Python versions), so the loop for i in d goes over 'lmn' and then 'abc', and each pass prints the key with %s and its value with %d. So the lines are 'lmn 123' and 'abc 345'. The other options swap the key and the value or print wrong values, and they also have a stray quote mark in the title line.
Marks
Total number of questions : 2
Number of answered questions : 0
Number of unanswered questions : 2