There are four collection data types in the Python programming language :
Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in a list are called elements or sometimes items. There are several ways to create a new list; the simplest is to enclose the elements in square brackets ( [ and ] ): 1. [10,20,30,40]
2. ["your name","your age","address"]
The first example is a list of four integers. The second is a list of three strings. The elements of a list don’t have to be the same type. python also have nested list feature (A list within another list is nested) : ["ayan",1,["age",24]]
Creating a list is as simple as putting different comma-separated values between square brackets. To access values in lists, use the square brackets for slicing along with the index or indices to obtain value available at that index.
|
You can loop through the list items by using a for loop:
|
To determine if a specified item is present in a list use the in keyword:
|
python list have built-in methods, methods help us to manipulate list items.
|
Python includes many built-in methods but here we just adding some of the following built-in methods to manipulate lists :
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.