23
loading...
This website collects cookies to deliver better user experience
list=[[1,2,3],[2,3,4],[3,4,5]]
>>> list=[[1,2,3],[2,3,4],[3,4,5]]
>>> print(list[1])
[2, 3, 4]
>>> print(len(list))
3
>>> print(list[2][1])
4
>>> print(len(list[0]))
3
>>> print(list)
[[1, 2, 3], [2, 3, 4], [3, 4, 5]]
>>> for i in range(0,len(list)):
... for j in range(0,len(list[i])):
... print(list[i][j])
...
1
2
3
2
3
4
3
4
5
>>> for i in list:
... for c in i:
... print(c,end="")
... print()
...
123
234
345
a=[]
r=int(input("Please enter the number of rows "))
c=int(input("Please enter the number of columns "))
for i in range(r):
#Append an empty sublist
a.append([])
for j in range(c):
num=int(input("Enter a value "))
a[i].append(num)
print(a)
for i in a:
for j in i:
print(j, end="\t")
#here, "\t" stands for tab, i.e. leave spaces
print()
Please enter the number of rows 3
Please enter the number of columns 2
Enter a value 1
Enter a value 2
Enter a value 3
Enter a value 4
Enter a value 5
Enter a value 6
[[1, 2], [3, 4], [5, 6]]
1 2
3 4
5 6
>>> a=('Aatmaj','Zephyr',163,'1234')
>>> b=(1,2,3,4,5)
>>> c='a','b','c','d'
>>> print(a)
('Aatmaj', 'Zephyr', 163, '1234')
>>> print(len(a))
4
>>> print(a[3])
1234
>>> d=((1,2,3),a,b,('a','c','2',5))
>>> print(d)
((1, 2, 3), ('Aatmaj', 'Zephyr', 163, '1234'), (1, 2, 3, 4, 5), ('a', 'c', '2', 5))
>>> print(len(d))
4
>>> print(len(d[1]))
4
>>> print(d[2][3])
4
>>> print(d[4][2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> a.append(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'append'
1 2 3
a= 4 5 6
7 8 9
147
258
369
1
45
789
123
45
7