How to change tuple's existing elements?

0 votes
Hi ,
I am having a problem during modify the existing elements in tupple.

variable = (1, 2)
>>> variable += 1

TypeError: 'tuple' object does not support item assignment

expected output will be:

variable=(2,2)
Jul 2 in Python by Priyankar

edited Jul 2 12 views

1 answer to this question.

0 votes

Hi Priyankar,

I understand your problem,

but

Tuple is immutable - you can't modify them.

int is immutable - you can't modify them.

so, in this case, you need to use set in a list instead of a tuple

answered Jul 2 by Sampriti
• 860 points

Related Questions In Python

0 votes
1 answer

How to change one character in a string in Python?

Python strings are immutable, you change them ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,500 points
36 views
0 votes
1 answer

How can I change the data type to string in Python?

You can use str(variablename) This is called conversion ...READ MORE

answered Dec 17, 2018 in Python by Shuvodip
44 views
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2 in Python by Omkar
• 67,120 points
43 views
0 votes
1 answer

How to change python version into 3.7.2 for entire pycharm jetbrains IDE projects?

Navigate to the Project page, select the configured interpreters ...READ MORE

answered Feb 27 in Python by Priyaj
• 56,160 points
44 views
0 votes
1 answer
0 votes
1 answer

How can I match tuple elements with list elements

It's better if you convert your eagles ...READ MORE

answered Sep 7, 2018 in Python by ariaholic
• 7,320 points
30 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 130 views
0 votes
1 answer

How to drop missing value in python data-frame?

Hi Sarada,  I understand you are having problems with ...READ MORE

answered May 27 in Python by Sampriti
• 860 points
23 views