+ 1
What is output for below? How to get result 2 without changing print statement? How to change value in tuple?
a=(1,2) a[0]+=1 print(a[0])
3 Answers
+ 5
Zahed Shaikh ,
modify line 1 like this:
make tuple a list by using list(...)
in the original code line 2 creates an error, because tuple (a is a tuple) does not support item assignment, as tuple is immutable data structure. so we just create a list from the tuple, and the output will be 2 without modifying print statement.
happy coding and good success!
+ 1
a=(1,2)
print(a[0]+1)
you can get result 2
+ 1
Without changing print statement?