[issue46093] 2D array issue

Ritvik S report at bugs.python.org
Thu Dec 16 00:16:24 EST 2021


New submission from Ritvik S <ritviksetty at gmail.com>:

I had a problem running the following code. When I ran through what I thought python was supposed to do, I got a different answer than what python did. I think this is an error. Here is the code:



problem_ary = [['a','b','c'],['d','e','f'],['g','h','i']]
normal_ary = ['a','b','c']

print(normal_ary[:]) #should print ['a','b','c']
print(problem_ary[:][1])



The second output should be ['b','e','h'] since the print statement tells python to take [0][1],[1][1], and [2][1] from the problem_ary which is 'b','e','h'. It confused me when python instead returned ['d','e','f']. I came across this problem when I was trying to create tic-tac-toe in python. I tried coding this is Python 3.8, 3.9, and using an online interpreter, and I got the same result every time.

----------
files: 2D-Array-Problem.py
messages: 408671
nosy: ritviksetty
priority: normal
severity: normal
status: open
title: 2D array issue
type: behavior
versions: Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50498/2D-Array-Problem.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46093>
_______________________________________


More information about the Python-bugs-list mailing list