List, Tuple and Dictionary in Python
Lists A list is a sequence List Items List items are ordered, changeable, and allow duplicate values. List items are indexed, the first item has index [0] , the second item has index [1] etc. List Length To determine how many items a list has, use the len() function: Example Print the number of items in the list: thislist = [ "apple" , "banana" , "cherry" ] print ( len (thislist)) Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in list are called elements or sometimes items . There are several ways to create a new list; the simplest is to enclose the elements in square brackets (“[" and “]”): [ 10 , 20 , 30 , 40 ] [ 'crunchy frog' , 'ram bladder' , 'lark vomit' ] The first example is a list of four integers. The second is a list of three strings. The elements of a list don’t have to be the same type. The following list contains a string...