+ 3
Can you please explain the output of this code?
shiv = (11, 5, 7, 2, 2) shiv = str(shiv) print(shiv[2]) Answer is 1
2 Answers
+ 11
All JUMP_LINK__&&__Python__&&__JUMP_LINK Challenges are welcomed đ€
You are converting a tuple into a string. So all braces as well as number and separator is part of string so on printing index 2 elements it will print 1 as output
0-> (
1-> 1
2-> 1
3-> ,
And so on
+ 2
shiv=(11,5,7,2,2)
When you convert tuple into a string - str(shiv) - you just need to add ââ at the beginning and at the end of a tuple.
So str(shiv)==â(11,5,7,2,2)â. Each character becomes an element of a string.



