+ 1

how to fetch a value from tuple

21st Jul 2019, 12:45 PM
yash gupta
yash gupta - avatar
4 Respostas
+ 4
Like you do it with lists - by indexing. t = (1, 2, 3) print(t[2]) Output: 3
21st Jul 2019, 1:00 PM
HonFu
HonFu - avatar
+ 3
Just specifying its index For example, tup=('4','5','6') print(tup[1]) Output: 5
21st Jul 2019, 1:01 PM
deeyae
deeyae - avatar
+ 1
By index with square bracket like you would a list. You can use slicing just like a list also. tup = (1,2,3) tup[0] tup[-1] tup[1:] etc...
21st Jul 2019, 1:03 PM
James
James - avatar