Thursday 25 July 2019

Python multiple dimension array with range function has negative indexes

I am trying to define a two dimension array with for loops using range function:



>>> takobaba =  [['A' for i in range(0, 6, 1)] for j in range(0, 6, 1)]
>>> takobaba [-1][-1]
'A'


As you can see i get an output for index -1, -1 even i called range function from 0 to 6 with step 1 for both dimensions. Could you please help me to understand the reason and fix this error?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...