← Quiz: The collections Module: all 10 questions
Quiz: The collections Module · Question 7 of 10
How do you get a changed copy of a namedtuple s with a new cgpa?
How do you get a changed copy of a namedtuple s with a new cgpa?
- A.s.cgpa = 9.1
- B.s._replace(cgpa=9.1)
- C.s.update(cgpa=9.1)
- D.namedtuple.set(s, "cgpa", 9.1)
Answer & explanation
Correct answer: s._replace(cgpa=9.1)
_replace returns a new tuple because the original is immutable.
Can you get the rest right without peeking?
Take the timed Quiz: The collections Module quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →