dictionary to list in python
list in python methods
In this post we are going to learn about List in Python. Let's start..!
First What is List ? List is a datatype in Python. I have already explained all datatypes of Python in previous post. If you don't know about List or Datatypes in Python. Then check my post Datatypes in Python.
Or simply Click here This will open a post Datatypes in Python.
In List you can store values of any datatype or You can store list inside a list as well. But How ?
Suppose we have a list named as Mylist = [ 10, "sid", 99.9, True ]
Here we have various inbuilt function to work with list. That is
1} append( ) :
This function adds a new element or value to a list but in last position. This function takes a single parameter as a variable or actual value.
Syntax : list_name.append( parameter )
For ex. We want to add a name Jack in Mylist. We will simply write Mylist.append( "Jack" ).
2} clear( ) :
This function of List removes the all elements or values from list. This function does not take any parameter.
Syntax : list_name.clear( )
For ex. We want to remove all values from Mylist. We will simply write Mylist.clear( ) .
3} count( ) :
This function used to count how many values are present in list same as a value given as parameter. This function takes a variable or actual value as a parameter.
Syntax : list_name.count( parameter )
For ex. We want to check how many times the value 10 is present in list. We will simply write Mylist.count( 10 ) .
4} copy( ) :
This function of List returns a same copy of a original list. This function does not take any parameter.
Syntax : list_name.copy( )
For ex. We want a same copy of Mylist. We will simply write Mylist.copy( ) .
5} extend( ) :
This function of List is used to extend the original list. This function takes a list, set, tuple as a parameter.
Syntax : list_name.extend( parameter )
For ex. We want to extend a Mylist with values of another list. We will simply write Mylist.extend( new_list_name ) .
6} insert( ) :
This function of List is used to add new value in original list but on specified position. This function takes two parameters first a index number and second a variable or actual value.
Syntax : list_name.insert( index_no, value )
For ex. We want to add a new value 100 on index no 2 in Mylist. We will simply write Mylist.insert( 2, 100 ).
7} reverse( ) :
This function of List is used to reverse the value of list. This function does not takes any parameter.
Syntax : list_name.reverse( )
For ex. We want to reverse all values in Mylist. We will simply write Mylist.reverse( ).
7} remove( ) :
This function of List is used to remove the value from list. This function takes a variable or actual value parameter.
Syntax : list_name.remove( )
For ex. We want to remove value "sid" from Mylist. We will simply write Mylist.remove( "sid" ).
Now How to store list inside list ?
This is very simple suppose we have list_num = [ 1, 2, 3 ] and list_char = [ 'a', 'b', 'c' ]. Now we want to store this lists inside the list simply write any name to list I am giving Mylist here now store both lists Mylist = [ list_num, list_char ] .
These are some functions that we use for List. Create a list and try this all function.
If you have any doubts in this post then please ask me in comment section below. I will try to solve it.
If you like these post and you have learned something from this then share this post with your friends and family.
Keep learning always.....!!! 😇😇😇