Posts

Showing posts with the label python list

what is list in Python and it’s operations?

Image
​ Definition of List: A collection of values, or elements, that can have any data type is commonly known as Python list. A list is presented with square brackets [], in which the values are separated by commas. For example; a = [7, ‘rain', 5, 'frog', 4] Negative indexing: The first element in the list hold index 0, the position of first element starts with zero-indexing, where the second element  has index 1, and go on. Lists can be so long so that to reach the last element is the lists we can use negative indexing in which we count the elements from backward. The last element of the list has index -1, the second to last  has index -2, and go on. To select the last element "p' from the b elow mentioned list x , place -1 in square  bracket. The element has index -1, as  it is the last element of the lists. e.g. x = ['b', 'd', 'm', 'p'] print(x[-1]) print(x[-4]) Result: p b Indexing and slicing:  For accessing the element in the Python...