Ticker

6/recent/ticker-posts

Python List:

 Python List:

List is a collection of multiple items, separated by commas inside a square bracket. It is used to store collection of datas.  There are 4 built in data types to store data, they are list, tuples, set and dictionaries. 

Creating List:

We can create a list of integers, strings or list of mixed data types. 

Creating List in Python


 You can also create an empty list and nested list.

Creating empty and nested list in python


 Accessing the items from the list:

Indexing in python starts from 0. By using the index operator [ ], the items from the list can be accessed. We can access by using positive index values and also negative index values.

 

Accessing items from the list

Accessing the items from the multi-dimensional list:

Accessing the items from multidimensional list


 Slicing the list in Python:

 

Slicing the list in python


Adding and changing the elements in list:

Elements can be changed in the list by using the particular index value and replacing it.

 

Adding elements in the list.

We can add elements to the list by ‘.append’

Adding elements in the list using append method in python
 

Concatenating lists:

We can join lists by using just ‘+’ operator.

 

Concatenating lists in python

Inserting elements in the list:

Elements can be inserted in the list by using insert ( ) method by specifying the location. First is the index position and the next is the element to be inserted.

 

Inserting an element in the list in python

Deleting elements in the list:

Using ‘del’ one or more elements can be deleted by specifying the index number.

 

Deleting the elements from the list in python


Inbuilt Python List Methods:

append( )= Adds elements in the end of the list

insert( )= Inserts an elements in the specified index location

count( )= Counts the number of  elements in the list

remove( )= Removes  elements from the list

sort( )= Sorting the elements in the ascending order in the list

reverse( )= Reversing the order of the items in the list

copy( ) = Returns the copy of the list








Post a Comment

0 Comments