๐Ÿ“Š Problem Solving and Python Programming
Q. What type of data is: a=[(1,1),(2,4),(3,9)]?
  • (A) array of tuples
  • (B) list of tuples
  • (C) tuples of lists
  • (D) invalid type
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (B) list of tuples

Explanation: the variable a has tuples enclosed in a list making it a list of tuples.

๐Ÿ“Š Problem Solving and Python Programming
Q. Is the following Python code valid? >>> a,b=1,2,3
  • (A) yes, this is an example of tuple unpacking. a=1 and b=2
  • (B) yes, this is an example of tuple unpacking. a=(1,2) and b=3
  • (C) no, too many values to unpack
  • (D) yes, this is an example of tuple unpacking. a=1 and b=(2,3)
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (C) no, too many values to unpack

Explanation: for unpacking to happen, the number of values of the right hand side must be equal to the number of variables on the left hand side.

๐Ÿ“Š Problem Solving and Python Programming
Q. Which of the following statements create a dictionary?
  • (A) d = {}
  • (B) d = {“john”:40, “peter”:45}
  • (C) d = {40:”john”, 45:”peter”}
  • (D) all of the mentioned
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (D) all of the mentioned

Explanation: dictionaries are created by specifying keys and values.

๐Ÿ“Š Problem Solving and Python Programming
Q. d = {"john":40, "peter":45}
  • (A) “john”, 40, 45, and “peter”
  • (B) “john” and “peter”
  • (C) 40 and 45
  • (D) d = (40:”john”, 45:”peter”)
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (B) “john” and “peter”

Explanation: dictionaries appear in the form of keys and values.

๐Ÿ“Š Problem Solving and Python Programming
Q. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
  • (A) d.delete(“john”:40)
  • (B) d.delete(“john”)
  • (C) del d[“john”]
  • (D) del d(“john”:40)
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (C) del d[“john”]

Explanation: execute in the shell to verify.

๐Ÿ“Š Problem Solving and Python Programming
Q. What is the use of seek() method in files?
  • (A) sets the file’s current position at the offset
  • (B) sets the file’s previous position at the offset
  • (C) sets the file’s current position within the file
  • (D) none of the mentioned
๐Ÿ’ฌ Discuss
โœ… Correct Answer: (A) sets the file’s current position at the offset

Explanation: sets the file’s current position at the offset. the method seek() sets the file’s current position at the offset.

Jump to