Python Forum

Full Version: strange output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why does
print([0][0])
output 0 ?
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
(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 !