Lists Vs. Arrays Top Differences

Here’re differences between Lists and Arrays. You’ll learn on how to create List and Arrays, and differences. Here’s how to work with Arrays using NUMPY.

Lists Vs. Arrays

Lists

  • List is mutable. You can change data.
  • List can have different types of data (it can have Heterogeneous data)
  • List is an ordered collection of data
  • List can grow and shrink dynamically as needed

Arrays

  • Array is mutable. You can change data
  • Array can have only one type of data
  • Array is an ordered collection of data
  • Array is fixed. It can’t grow and shrink.

Python Lists

1. Creating List

Here’s is logic how to create a List.

mylist = [] # empty list is created
mylist.append(1) # append() function is used to add elements into list
mylist.append(2)
mylist.append(3)
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
print(x)

2. List Operations

Various operation that you can do on Lists.

Python Code to Create List

Output

Python List Result

3. Heterogeneous Data

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])

Example:

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

Python Logic With Different Data-types

Output

Python List Output When it has Different type of data

References

Keep Reading

Free Downloads

12 Python Interview Questions
12 Python Interview Questions

Keep Reading

LATEST POSTS

AWS VPC Top Companies Interview Questions

Here’re the top interview questions on AWS virtual private cloud. This article covered VPC, subnet, Route Table, and the IGW.

CICS CEMT Resources That You Can Change Status

CEMT is Master Terminal Transaction in CICS. With the CEMT transaction, you can change the status for various resources such as Program, Mapset, File, Queue, Task, Terminal, and Transaction. CICS CEMT Command Examples CEMT SET FILE(name) { ENABLED | DISABLED } { OPEN | CLOSED } CEMT SET PROGRAM(name) { ENABLED | DISABLED } […

Loading…

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

Listen Audio

Audio Post

Get new content delivered directly to your inbox.

Author: Srini

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