Jan-17-2019, 08:23 AM
Hello!
I am new in Python and I have a question.
In the next code I want to print a 2D array in "C++ style"
Enter size of the rows: 2
Enter size of the cols: 3
tab[0][0] = 11
tab[0][1] = 12
tab[0][2] = 13
tab[1][0] = 21
tab[1][1] = 22
tab[1][2] = 23
[] 11 12 13 21 22 23
Why square brackets at the beginning ?
There are many ways to print the 2D array in Python ?
I am new in Python and I have a question.
In the next code I want to print a 2D array in "C++ style"
tab = [[]]
rows = int(input("Enter size of the rows: "))
cols = int(input("Enter size of the cols: "))
for i in range(0, rows):
for j in range(0, cols):
arr = int(input("tab[{}][{}] = ".format(i,j)))
tab.append(arr)
print()
for i in range(len(tab)):
print(tab[i], end = " ")
print()For a tab[2][3] the below code will print:Enter size of the rows: 2
Enter size of the cols: 3
tab[0][0] = 11
tab[0][1] = 12
tab[0][2] = 13
tab[1][0] = 21
tab[1][1] = 22
tab[1][2] = 23
[] 11 12 13 21 22 23
Why square brackets at the beginning ?
There are many ways to print the 2D array in Python ?
