Friday 4 December 2015

Python: list: append an element

List data type provides ‘append’ method to append an element to a list.

test.py
list=[2, 4, 6]
print(list)

list.append(8)
print(list)

list.append(10)
print(list)

$ python3 test.py
[2, 4, 6]
[2, 4, 6, 8]
[2, 4, 6, 8, 10]




Previous                                                 Next                                                 Home

No comments:

Post a Comment