+ 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])

29th Jun 2021, 2:04 PM
Zahed Shaikh
Zahed Shaikh - avatar
3 Respostas
+ 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!
29th Jun 2021, 7:11 PM
Lothar
Lothar - avatar
+ 1
a=(1,2) print(a[0]+1) you can get result 2
29th Jun 2021, 2:11 PM
Abhishek Kumar
Abhishek Kumar - avatar
+ 1
Without changing print statement?
29th Jun 2021, 2:17 PM
Zahed Shaikh
Zahed Shaikh - avatar