In this source code example, we create a list in Python and demonstrates the usage following methods:
1) insert()
2) remove()
3) append()
4) len()
5) pop()
6) clear()
Python list - insert, remove, append, len, pop, and clear example
a=[1,3,5,6,7,[3,4,5],"hello"] print(a) a.insert(3,20) print(a) a.remove(7) print(a) a.append("hi") print(a) len(a) print(a) a.pop() print(a) a.pop(6) print(a) a.clear() print(a)
Output:
[1, 3, 5, 6, 7, [3, 4, 5], 'hello'] [1, 3, 5, 20, 6, 7, [3, 4, 5], 'hello'] [1, 3, 5, 20, 6, [3, 4, 5], 'hello'] [1, 3, 5, 20, 6, [3, 4, 5], 'hello', 'hi'] [1, 3, 5, 20, 6, [3, 4, 5], 'hello', 'hi'] [1, 3, 5, 20, 6, [3, 4, 5], 'hello'] [1, 3, 5, 20, 6, [3, 4, 5]] []
Comments
Post a Comment