In this post, you will find differences between arrays and lists in Python. By default Python does not support arrays, but it supports Lists. You need NUMPY package, if you want to work with Arrays.
Differences Between Arrays and Lists in Python
- Arrays can have the same type of data, but Python doesn’t support. You need Numpy.
- Python supports Lists. You can find here best examples for LISTS.
1. How to Create a List in Python
mylist =  # empty list is created
mylist.append(1) # append() function is used to add elements into list
print(mylist) # prints 1
print(mylist) # prints 2
print(mylist) # prints 3
# prints out 1,2,3
for x in mylist: # for loop is used
You Might Also Like: How to Remove Duplicates in List
2. List Operations in Python
4. How List is different from Array
List supports heterogeneous data.
list1 = ['physics', 'chemistry', 2018, 2019]; # It has both numeric and strings
list2 = [1, 2, 3, 4, 5, 6, 7]; # It has only numeric values
print ("list1: ", list1)
print ("list2[1:3]: ", list2[1:3])
5. List Can Have Heterogeneous Data
In the below example you can find both numeric and Strings.
6. The Output
The LIST in Python is a group of values separated by commas and enclosed in square brackets. I have a point to share with you. LIST is mutable. That means you can manipulate data present in the Lists. Here is a list of operations you can do with a List.