Slicing and Immutability of Tuples | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

Slicing and Immutability of Tuples

Hello, In a quiz it was asked can Tuples be sliced and the answer was yes. Again in next questions it was asked whether they are an immutable list, and the answer was Yes. Since, list are mutable and hence can be sliced so how can tuples be when they are immutable? Thanks, for answering. I am still learning so excuse me if I had asked silly question.

18th Aug 2017, 10:54 AM
Pavan Dubey
Pavan Dubey - avatar
1 Antwort
I am oversimplifying this but... Tuples are plain lists that "behave" as immutable. Like many other Data Structures in Python, they aren't really that immutable, because they can contain mutable objects within them. However, that has nothing to do with slicing a tuple. Slicing a tuple will generate another tuple but will not mutate the original tuple, so that tuple will still be the same tuple as it was before it was sliced(unless you self assign it.)(That is too many 'tuple's in a sentence.)
21st Jun 2020, 10:52 AM
Anubhav Mattoo
Anubhav Mattoo - avatar