Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
リストの内容を印刷すると、次の出力が得られました。
[[...], [...], [...], [...], [...], [...]]
これらの奇妙な点は何ですか?
Python2.7.3を使用しました
おそらく、自分自身への参照を含むリストを誤って作成した可能性があります (または、ここでは多くの参照):
>>> a = ['x'] >>> a ['x'] >>> a[0] = a >>> a [[...]]
3 つのドットが使用されるのは、文字列表現が再帰に溺れないようにするためです。idこれは、およびis演算子を使用して確認できます。
id
is
>>> id(a) 165875500 >>> id(a[0]) 165875500 >>> a is a[0] True