Python Arrays Vs Lists With Examples

Photo by Kevin Bhagat on Unsplash

Python arrays and lists both not the same. I have explained the differences between these two. And this is an interview question.

Arrays can have the same type of data, either numeric or strings. And Python does not have built-in support for Arrays but supports Lists.

In this post, you can find the best examples for List. So that you will know the rules to use List. In List, you can have data of different types.

Python does not have built-in support for Arrays. If you want to work with arrays, you need to import Numpy.


1. List Examples 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

2. Commands to Manipulate Data in List

3. Output

4. List Supports non-homogeneous 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 Different Data-types

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.


Python In — Depth: Use Python Programming Features, Techniques, and Modules to Solve Everyday Problems (English Edition)




Sr.Software Developer - Technology

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

March LeetCoding Challenge 2021 — Day 3: Missing Number

Contract Management Software as a Risk Management Solution


TryHackMe: Kenobi

A Beginner’s Guide to Installing Jupyter Notebook Using Anaconda Distribution

The Plan — Stage One: Inception

FIFA 19 — Neymar JR

Setup your first Python Flask Web Application on Docker Swarm

Python Frameworks for Web Development — 2022

Why Scrum Is No Longer My First Choice

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Sr.Software Developer - Technology

More from Medium

13 Advanced Python Scripts For Everyday Programming

A Power-Packed Light Reading on Data Structures

Build your own event system in python

Try import pdb and pdb.set_trace() to debug your python code better