List in Python - Introduction

First of all, let us discuss here that what is a list in Python? Basically, in Python list is just like data structure and it is a erratic or uncertain order or sequence of elements. Any value or element, entered into the list is known as item.

In Python, List is the most flexible datatype as the values or items can be easily written by separated through comma between square brackets [ ].So, we can say that Lists are as similar as arrays that is used in other programming languages. Lists are not alike always and that's makes it a most powerful tool in Python.

The positive aspects of list are:

  • In a single list any datatype can be added like Integers, Strings or Objects.
  • It is quiet worthwhile for executing stacks and queues.
  • Lists are flexible and can be modified after the creation as well.

How to create a list?

In Python, you just need to enter the items within the square brackets [ ] to create the list. In list, duplicate numbers or values can be inserted multiple times but at different positions.


Create Different Types of Lists:

# empty list mylist = [ ] # list of numbers mylist = [2, 3, 4, 5] #list with mixed datatypes mylist = [2, “dzone”, 4.5] # nested list mylist = [“dzone”, [4, 6, 8], ['c']]

How to use list in Python?

List is used in Python to store numerous datatypes in a single shot. The Python Lists have a definite count and has proper order. Each and every item in a list has its particular place in the given list and it allows duplicate items as well which also has its own place and credibility.