Lists Vs. Arrays Top Differences

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

  1. Arrays can have the same type of data
  2. 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[0]) # prints 1
print(mylist[1]) # prints 2
print(mylist[2]) # 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

Python Code to Create List

3. Output

Python List Result

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[0]: ", list1[0])
print ("list2[1:3]: ", list2[1:3])

5. List Can Have Heterogeneous Data

In the below example you can find both numeric and Strings.

Python Logic With Different Data-types

6. The Output

Python List Output When it has Different type of data

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. 

Keep Reading

Free Downloads

12 Python Interview Questions
12 Python Interview Questions

Keep Reading


SQL Query: How to Use LOCATE and Substring Correctly

Here are SQL queries to use the SUBSTRING function along with LOCATE function. LOCATE gives position, and SUBSTRING uses that for the start position.

Python Logic to use tell() and seek()

In Python, both tell and seek functions help you get the data from a file. How to use these explained on how to use in your current project.

11 Kafka Admin Interview Questions

You can learn interview questions for the Kafka administrator role here. The questions covered prime points of the Kafka server.


Something went wrong. Please refresh the page and/or try again.

Listen Audio

Audio Post

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.