Python Forum
basic question about tuples and immutability
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
basic question about tuples and immutability
#2
You can't add or delete elements to tuple but, the existing elements can be modified if they are mutable type.

>>> tup = (1,'a',[1,2])
>>> tup[2][1] 
2
>>> tup[2][1] = 3
>>> tup
(1, 'a', [1, 3])
>>> tup[2].append(4)
>>> tup
(1, 'a', [1, 3, 4])
Here, the list in the tuple can be modified but not rest of the elements.
You can change existing items in list or add or delete items in List as it is mutable.
Reply


Messages In This Thread
RE: basic question about tuples and immutability - by omm - Oct-18-2020, 01:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic Coding Question: Exit Program Command? RockBlok 3 670 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  [solved] Basic question on list matchiing paul18fr 7 1,973 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
  Very basic calculator question BoudewijnFunke 4 2,032 Dec-10-2021, 10:39 AM
Last Post: BoudewijnFunke
  Simple code question about lambda and tuples JasPyt 7 3,489 Oct-04-2021, 05:18 PM
Last Post: snippsat
  basic question isinstance tames 5 2,933 Nov-23-2020, 07:20 AM
Last Post: tames
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,190 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  Basic Beginner question NHeav 4 2,897 Sep-13-2019, 11:43 AM
Last Post: NHeav
  Basic coding question with Python Than999 3 3,202 Jul-17-2019, 04:36 PM
Last Post: jefsummers
  basic question???????? cemdede 2 2,412 Jan-18-2019, 03:05 AM
Last Post: ntd9395
  basic plotting question Devilish 0 1,934 Dec-27-2018, 10:35 PM
Last Post: Devilish

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020