Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strange output
#1
Why does
print([0][0])
output 0 ?
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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 !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange output kintarowonders 6 2,886 May-08-2020, 05:20 PM
Last Post: buran
  Strange output with regular expressions newbieAuggie2019 1 1,899 Nov-04-2019, 07:06 PM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020