9
a = [2]
a.append(a)

And I print a,

[2, [...]]

Also I print a[1][0]

2

What is [...] ? and when I print a[1][0], print 2, not [...] ?

3
  • [...] means that it's a list but the print not displaying its content. Commented Jan 13, 2017 at 9:22
  • 4
    good question, but I'm puzzled about the title. What's to do with garbage collection? Commented Jan 13, 2017 at 9:29
  • I am watching Python Tutorial, garbage collection youtube, that code is in there. so I think that code is related to garbage collection Commented Jan 13, 2017 at 9:32

2 Answers 2

7

... is the ellipsis object. Here it is issued because else it would print forever! (due to infinite recursion)

and: print(a[1][0]):

a[1] is a so a[1][0] is 2, like a[1][1][1][1][0] is 2 too.

Sign up to request clarification or add additional context in comments.

I just edited. Ellipsis operator is something else. I'll use your link. and it's not pedantic. Thank you very much.
Thanks ! and, It means [2, [2, [2, [2, ~ ]], is it right?
A bit like the larsen you'd get when you're filming your own TV while feeding your image to it :) Actually it means "there are other things but I cannot show them". But it could be issued in other situations.
2

Ellipsis ... is used for slicing multidimensional numpy arrays.

The ellipsis syntax may be used to indicate selecting in full any remaining unspecified dimensions.

a[1] is [2, [...]]

so, a[1][0] is 2.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.