Thursday , September 19 2024

Which of the following sentences are true about the code? (Select two answers) nums = [1, 2, 3] vals = nums

Questions BankCategory: Python Essentials 1Which of the following sentences are true about the code? (Select two answers) nums = [1, 2, 3] vals = nums
Which of the following sentences are true about the code? (Select two answers)

nums = [1, 2, 3]
vals = nums
  • nums and vals are different lists
  • nums has the same length as vals
  • nums and vals are different names of the same list
  • vals is longer than nums

Explanation: Assigning nums to vals creates a situation in which the same list (i.e. [1, 2, 3]) has two different names. Giving a new name to an existing list, in our case vals to nums, is called aliasing. And since nums and vals are two different names that refer to the same object, they also have the same length (3).

More Questions: Python Essentials 1 (PE1) Course Final Test