Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Introduction

Listfooter line

Lists are just like dynamically sized arrays, declared in other languages (vector in C++ and ArrayList in Java). Lists need not be homogeneous always which makes it the most powerful tool in Python. A single list may contain DataTypes like Integers, Strings, as well as Objects. Lists are mutable, and hence, they can be altered even after their creation.

 

List in Python are ordered and have a definite count. The elements in a list are indexed according to a definite sequence and the indexing of a list is done with 0 being the first index. Each element in the list has its definite place in the list, which allows duplicating of elements in the list, with each element having its own distinct place and credibility.

 

Example:

 

>>> a = [] #Here we are creating onedimensional(1-D)List.

>>> a

 

output:

 

[]

 

Characteristics of Lists

The list has the following characteristics:

  • Lists in python are ordered.
  • The elements of a list can be accessed by their indices.
  • Lists are mutable.
  • A list can store a number of various/different elements.

List indexing

 

 

Example:

 

list = [0,1,2,3,4,5]
print(list[0])
print(list[2])
print(list[-1])
 
output:
0
2
5