List Function in python

List Function in Python

Hello Friends, I am Nirav. And in this tutorial I going to show you how to use Variable and datatype in Python..
So, Let's get Started




So, Friends as you know List function is basic function to remember all thing in one variable.

Why we use List ?

          To store data in to one variable name

How To Create List ?

          In Python programming, a list is created by placing all the items (elements) inside a square bracket [ ], separated by commas.
It can have any number of items and they may be of different types (integer, float, string etc.).

How to access elements from a list?

There are various ways in which we can access the elements of a list.
          
          1 ) List Index
                          In Index operator we can access any item from the list. If in list there are
                  any numbers of element than you access any element from the list.
                           Index starts from 0. So, a list having 5 elements will have index from
           0 to 4.

      2 ) Negative indexing

                  Python allows negative indexing for its sequences. The index of -1  
             refers to the last item, -2 to the second last item and so on.              

How to access more than one element at a time ?

          We can access more than one element using Colon..

How to add element in list ?

          What if you want to enter a new element in list so, it's possible by using append().
What ever you write in append it will be last element of list.

          And what if you want to enter a number of elements at a time so, it's possible by using extend([]). What ever you write in extend it will be added in list

How to change element in list ?

          What if you want to change element in list it's possible in python.




How to delete or remove elements from a list? 

          1) Using del
                       We can delete one or more items from a list using the keyword delIt             can even delete the list entirely. it will delete your element by element's               position.


          2) Using remove()
                           We can delete any specific item from list using remove().



Python List Methods

          1) index()
                         Using Index() you will know that at which position your element is alive.

In upper Example your element 2 is alive on position number 2.

          2)count()
                    Using count() you will know how many time your element will be repeat in list.
In upper Example 5 will be repeat 2 times.

          3)sort()
                    Using sort() you will able to sort your list.

          4)reverse()
                       Using reverse() you will able to  reverse your list

 You also visit my YouTube video regarding to this Topic

https://youtu.be/utmgdsXtjCI



Comments

Popular posts from this blog

Loop Control Statement

Function in python

Boolean Expression and If..else Condition