Python Forum
strange output - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: strange output (/thread-22586.html)



strange output - KaliLinux - Nov-18-2019

Why does
print([0][0])
output 0 ?


RE: strange output - buran - Nov-18-2019

left-hand [0] is a list with one element - 0.
the right-hand [0] is indexing - you access the 0-indexed element, which is 0

to be more clear
print([1][0])
will print 1


RE: strange output - KaliLinux - Nov-19-2019

(Nov-18-2019, 08:31 PM)buran Wrote: left-hand [0] is a list with one element - 0.
the right-hand [0] is indexing - you access the 0-indexed element, which is 0

to be more clear
print([1][0])
will print 1

Now I understand, thanks !