Here are differences between Lists and Arrays. You will learn on how to create List and Arrays, and differences.
You May also Like: how to work with Arrays using NUMPY.
Lists Vs. Arrays
- Arrays can have the same type of data
- Lists supports Heterogeneous data.
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.