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:

Jul 2 in Python by Priyankar

edited Jul 2 29 views

1 answer to this question.

0 votes

Hi Priyankar,

I understand your problem,


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
• 1,100 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,520 points
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
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,660 points
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,920 points
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,340 points
+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 341 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
• 1,100 points