+ 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

9th Mar 2020, 7:41 AM
APC (Inactive for a while)
APC (Inactive for a while) - avatar
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
9th Mar 2020, 7:48 AM
MsJ
MsJ - avatar
+ 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.
9th Mar 2020, 9:27 AM
Mikhail Solovyev
Mikhail Solovyev - avatar