How to use list.append(obj) in Python

2 Answers

0 votes
lst = [123, 'C++', 'PHP', 'Python']
lst.append(3000)
print(lst)

'''
run:

[123, 'C++', 'PHP', 'Python', 3000]

'''

 



answered Mar 4, 2016 by avibootz
0 votes
lst2d = [[], []]

lst2d[0].append(1)
lst2d[0].append(22)

lst2d[1].append(3)
lst2d[1].append(444)

print(lst2d)

for row in lst2d:
    for column in row:
        print(column, end=" ")
    print(end="\n")

'''
run:

[[1, 22], [3, 444]]
1 22
3 444

'''

 



answered Mar 4, 2016 by avibootz

Related questions

1 answer 247 views
1 answer 176 views
2 answers 196 views
1 answer 148 views
1 answer 137 views
3 answers 206 views
...