Sunday, December 17, 2017

1).Python lists are the data structure that is capable of holding different type of data.
2).Python lists are mutable i.e., Python will not create a new list if we modify an element in the list.
3).It is a container that holds other objects in a given order. Different operation like insertion and deletion can be performed on lists.
4).A list can be composed by storing a sequence of different type of values separated by commas.
5).A python list is enclosed between square([]) brackets.
6).The elements are stored in the index basis with starting index as 0.
A list can be created by putting the value inside the square bracket and separated by comma.
Syntax:
1.    <list_name>=[value1,value2,value3,...,valuen];  
For accessing list :
1.    <list_name>[index]  
List Operations:
Various Operations can be performed on List. Operations performed on List are given as:
a) Adding Lists:
Lists can be added by using the concatenation operator(+) to join two lists.
Eg:
1.    list1=[10,20]  
2.        list2=[30,40]  
3.        list3=list1+list2  
4.        print list3  
Output:
1.    >>>   
2.        [10, 20, 30, 40]  
3.        >>>  

1.        

Functions and Methods of Lists:

There are many Built-in functions and methods for Lists. They are as follows:
There are following List functions:
There are following built-in methods of List:
MethodsDescription
index(object)Returns the index value of the object.
count(object)It returns the number of times an object is repeated in list.
pop()/pop(index)Returns the last object or the specified indexed object. It removes the popped object.
insert(index,object)Insert an object at the given index.
extend(sequence)It adds the sequence to existing list.
remove(object)It removes the object from the given List.
reverse()Reverse the position of all the elements of a list.
sort()It is used to sort the elements of the List.
FunctionDescription
min(list)Returns the minimum value from the list given.
max(list)Returns the largest value from the given list.
len(list)Returns number of elements in a list.
cmp(list1,list2)Compares the two list.
list(sequence)Takes sequence types and converts them to lists.

No comments:

Post a Comment