What are Lists?
A list in Python is an inbuilt collection of items that can contain elements of multiple data types, which may be either numeric, character logical values, etc. It is an ordered collection supporting negative indexing. A list can be created using [] containing data values. Contents of lists can be easily merged and copied using Python’s inbuilt functions.
Example:
In this example, we are creating a list in Python. The first element of the list is an integer, the second a Python string, and the third is a list of characters.
Python3
# creating a list containing elements # belonging to different data types sample_list = [ 1 , "Yash" , [ 'a' , 'e' ]] print ( type (sample_list)) print (sample_list) |
Output:
<class 'list'>
[1, 'Yash', ['a', 'e']]
Difference between List and Array in Python
In Python, lists and arrays are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements. In this article, we will see the difference between the two.
Contact Us