Understanding Lists in Python Like a Pro

Lists
A list is a data type in Python and also a data structure because it stores a collection of data. This is why it is considered a built-in data structure in Python. A list is defined using square brackets [ ], and the elements inside it are separated by commas ( , ). In a list, we can store elements of any data type, including another list (nested lists).
Lists are mutable in nature, which means that once a list is created, we can change or modify its elements at any point in the code. you can understand how list look using given image below

Indexing of list
We can also check index of the the element in list using index( ) method if you remember when we discuss about string we learned index( ) method here is same method. you can understand how index method work in list using image given below.

list methods
1. append( )
it is used to add element in list in last index.

2. remove( )
it remove first occurrence specified in remove method element from list.

3. clear( )
it remove all element from list.

4. count( )
Returns the number of times a specified element appears in the list.

5. max( )
return element which is greater than all of element present in list.

6. min( )
return element which is smallest than all of element present in list.

7. pop( )
remove last element from list.

we can also specify index but if index is out of range it return error so be careful when you use index in pop method.

8. reverse( )
reverse the order of list.

9. insert(index , element)
insert element in specified index in list.

10. sort( )
sort the list by increasing order.

11. extend( )
add another list element in the existing list.

we can use + operator for adding two list.

you can understand difference between extend and ‘+’ operator
extend → add element or another list in existing list we do not have to use 3rd list.
+ operator → we have to use 3rd variable to add two list.
that is major difference between them.
Comparison of tuples
the comparison of two tuples done on based on their first element.


note = > jb bhi comparison operator laga rhe hai calways check ki dno ke element same datatype ke hai ya nii.

#chaicode



