Posts

Showing posts from December, 2020

Python for Beginners : List_Clarifications_1

Image
 Removing all the occurrences of an element in a List listname.remove(element) - removes an element from the given list. If an element occurs more than once in a list, the first occurrence of that element will be removed.  To remove all the occurrences of an element from the given list, list comprehension technique can be used. By using this technique, all the other elements, except the given element, are moved to the same list.

Python for Beginners : List_Part_4

 Other methods : len(listname) -  returns the number of elements a list has. max(listname) - returns the maximum value from a list. min(listname) - returns the minimum value from a list. listname.count(element) - returns the number of occurrence of an element in a list. listname.index(element) - returns the index (position) of an element. listname.reverse() - reverses the order of elements in a list. listname.sort() - arranges the elements of a list in ascending order. listname.sort(reverse = True) - arranges the elements of a list in descending order.

Python for Beginners : List_Part_3

Image
  Modifying a List: Deleting / Removing elements : 'del' keyword, pop(), remove(element) Adding new elements Updating an existing element   Deletion : using 'del' keyword, an element from a particular position can be deleted. Deletion : using pop( ), the last element from a list can be removed. Deletion : using remove( ), a particular element can be removed Adding new elements : using append( ), a single element or an object can be added to a list at the end. Adding new elements : using insert(index, element), an element can be inserted at a particular position in a list. Updating an existing element : Already existing element can be updated using assignment operator with a new element.

Python for Beginners : List_Part_2

Image
 Accessing elements in a List : Indexing and Slicing The elements in a LIST are separated by commas.  Every element has its own position (known as index) in a LIST.  The first element in the LIST starts at the index value 0 (zero).  To access elements, the corresponding index values are mentioned through indexing or slicing.

Python for Beginners : List_Part_1

Image
In Python, there are four important built-in data types such as List, Set, Tuple and Dictionary.  Lists are used to store more than one elements under a single variable name.  Lists are mutable, means the elements in a List are changeable.  Lists allow duplicate values.  New items will be added at the end of the list.