Lists in Python
list is an ordered set of elements or values enclosed in a brackets. The elements or values are separated by commas ( , )
example
a list can also have different type of data
each element in the list can be accessed by using the index number, python has both normal and reverse index number, example for getting the last item in mix variable
lists using range() function
we can use range( ) to create a list of certain range ,we should pass range function inside list function ,see example given below
the above code writes 20 to 60 numbers into the listx variable
Appending to a List
we can append elements to already existed elements in the list variable by using .append( ) function
index in lists
just like the strings, lists have indexes too, starts from 0, the first element will be zero and the last will be -1, we can access and modify any element because lists are mutable in python.
Lists are Mutable
the meaning of mutable is ,we can modify the list without creating a new list in process
as you noticed above,the id will be same after modifying the 0th index element ,this is called mutable
List Slicing
by slicing the list, we can create new lists from existing list by slicing to certain index, we required,syntax is given below
example