-20
squares=[8,7,3,-1]   
Print(squares[0])

The output of this program is 8 but I don't understand why? and what is this program do?

naveen
  • 51,042
  • 46
  • 158
  • 241
hgs
  • 101
  • 5
  • 3
    Look up some tutorials on Python lists. – 0buz May 20 '20 at 12:01
  • 3
    The reason you're getting heavily downvoted here is because this is a very basic question, and SO is not a replacement for tutorials. – klutt May 20 '20 at 12:22

2 Answers2

2
squares=[8,7,3,-1]

This create a list of 4 elements : 8, 7, 3 and -1.

Print(squares[0])

The print function will display a value. In your case it display the value squares[0]. Your list named squares have 4 values with indexes starting from 0, so :

Print(squares[0]) : 8
Print(squares[1]) : 7
Print(squares[2]) : 3
Print(squares[3]) : -1

Just look how list works in python to learn more.

Alexy
  • 642
  • 3
  • 17
0

This program creates a list called "squares" and then prints the first element of the list, which is 8. Pyhton uses 0-based indexing, so the first position of an iterable is 0.

Jeni
  • 780
  • 4
  • 17