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, 2019 in Python by Priyankar

edited Jul 2, 2019 3,286 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, 2019 by sampriti
• 1,120 points

Related Questions In Python

0 votes
1 answer
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,560 points
1,278 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 18, 2018 in Python by Shuvodip
998 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, 2019 in Python by Omkar
• 69,220 points
1,566 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, 2019 in Python by Priyaj
• 58,020 points
3,375 views
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 aryya
• 7,460 points
2,694 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,443 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 28, 2019 in Python by sampriti
• 1,120 points
1,504 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP