Thursday , September 19 2024

Take a look at the snippet, and choose the true statements: (Select two answers) nums = [1, 2, 3] vals = nums del vals[1:2]

Questions BankCategory: Python Essentials 1Take a look at the snippet, and choose the true statements: (Select two answers) nums = [1, 2, 3] vals = nums del vals[1:2]
Take a look at the snippet, and choose the true statements: (Select two answers)

nums = [1, 2, 3]
vals = nums
del vals[1:2]
  • nums and vals are of the same length
  • nums is longer than vals
  • nums and vals refer to the same list
  • nums is replicated and assigned to vals

Explanation: Remember that:

  • the assignment vals = nums does not create a new list, as vals is only another name for nums, and they both point to the same space in the memory,
  • if you delete any elements in vals, they are also deleted in nums.

More Questions: Python Essentials 1 – Module 3 Test