Machine-translated by Google. Questions are authored in English.
Top

Data Types and Operators Questions and Answers

1.

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]))

Exam Year(s)

DSSSB TGT - 2023,

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.

Please log in or register to report this question.

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.

Exam Year(s)

DSSSB TGT - 2023,

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.

Please log in or register to report this question.

Loading…
Tags: Data Types and Operators Questions and Answers || Data Types and Operators MCQ Questions and Answers || Data Types and Operators GK Questions and Answers || Data Types and Operators GK MCQ Questions || Data Types and Operators Multiple Choice Questions and Answers || Data Types and Operators GK || GK on Data Types and Operators || Computer Programming Questions and Answers || Computer Programming MCQ Questions and Answers || Computer Programming GK Questions and Answers || GK on Computer Programming