1

I declared a list inside a tuple like this,

a = ([x,y])

Now for accessing the first element xof the inner list I assumed we would have to use, a[1][1] .

But it gives an error of out of bounds and we can access the element simply like a[1]

Does this mean singleton tuple can also be declared like a([temp]) along with the usual a(temp,)? Or is it treated simply as a list?

How does python implement this? I could not find any concrete explanation or documentation.

  • 1
    It's not a tuple, just a list; without the comma the parentheses make no difference. – jonrsharpe Jan 10 '16 at 09:11
  • Thanks i got confused as i found another answer that said tuples can also be declared like `tuple(['temp'])`, In which tuple is actually the inbuilt function which skipped my mind. – user5729542 Jan 10 '16 at 09:22

0 Answers0