List, Tuple and Set in python List basic A list is also a sequence type, meaning the contained elements are ordered by position in the list, known as the element's index, starting with 0. my_list = [ ] creates an empty list with no elements. Adding and removing list elements Since lists are mutable, a programmer can use methods to add and remove elements in the list. A method instructs an object to perform some action and is specified by providing the object name followed by a "." symbol and then the method name. The append() list method is used to add new elements to a list. Elements can be removed from a list using the pop() or remove() methods. Methods are covered in greater detail in another section. Adding elements to a list: Operation Description list.append(value) Adds value to the end of the list. Ex: my_list.append("abc") ...
Comments
Post a Comment