Take a look at the snippet, and choose the true statements: (Select two answers)

Take a look at the snippet, and choose the true statements: (Select two answers)

nums = [1, 2, 3]

vals = nums

del vals[1:2]
A . nums is longer than vals
B. nums and vals refer to the same list
C. vals is longer than nums
D. nums and vals are of the same length

Answer: B,D

Explanation:

Topics: list referencing list slicing del

Try it yourself:

nums = [1, 2, 3]

vals = nums

del vals[1:2]

print(nums) # [1, 3]

print(vals) # [1, 3]

A list is a mutable data type.

Assigning a mutable data type creates a reference to the same object.

vals and nums will point to the same object in the memory

and when you change one you automatically change the other, too.

Latest PCEP-30-01 Practice Questions with 124 Q&As

Updated Study Material | Instant Download | Detailed Answers and Explanations

Subscribe
Notify of
guest
0 Comments