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.

Similar Reads

Operations Difference in Lists and Arrays

Accessing element is fast in Python Arrays because they are in a contiguous manner but insertion and deletion is quite expensive because all the elements are shifted from the position of inserting and deleting element linearly. Suppose the array is of 1000 length and we are inserting/deleting elements at 100 position then all the elements after the hundred position will get shifted due to which the operation becomes expensive....

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....

What are Arrays?

...

Difference Between List and Array in Python

An array is a vector containing homogeneous elements i.e. belonging to the same data type. Elements are allocated with contiguous memory locations. Typically the size of an array is fixed. Th e insertion and deletion costs are high as compared to the list however indexing is faster in the Arrays due to contiguous memory allocation. Arrays can be used by importing the array module....

Contact Us