What is a List in python ? How to create a List ?

Tech Programmer
1


WHAT IS A LIST IN PYTHON?


The python lists are containers that are used to store a list of values of any type. A list is a standard data type in python that can store a sequence of values belonging to any type. The Lists are depicted through square brackets[ ], eg following are some list in python: 

[ ]                                                                #empty list
[1,2,3]                                                        #list of integers
[1,2.5,9.8,9]                                               #list of numbers
['a', 'b', 'f', 'g', 'k', 'y']                                   #list of characters
['a', 9, 'b', 8, 'd', 5, 'm' ,7, 'n']                      #list of mixed elements
['Arjun', 'Bhim', 'Pandav', 'Mahabharat']    #list of strings


HOW TO CREATE A LIST ?


To crate a list put a number of expressions in square brackets. That is, use square brackets to indicate the start and the end of the list, and separate the items by commas.

Thus to create a list you can write in the form given below :

L = [ ]
L = [values, Values2, ..., ]

This construct is known as list display construct.


The Empty List :

The empty list is [ ]. It is equivalent to 0 or ' ' and like them it also has truth value as false. You can also create an empty list as L = list( ) it will generate an empty list and name it as L.


Long Lists :

If a list contains many elements , then to enter such long list, you can split it across several lines, as given - 

L = [100,7,6,23,9,3,59,86,35,9,21]

The brackets only appear in the beginning and at the end of the list.


Nested Lists :

A list may have an elements in it, which itself is a list. Such a list is called nested list example-

L = [12,45,[54,89,75],456,45,63]

L is a nested list with 6 elements and L[2] element is a list [54,89,75]. length of L is 6 as it counts [54,89,75] as one element. also as L[2] is a list [54,89,75], which means L[2][0] will give 54 and L[2][1] will give 89.


Less Info. Is Not Sufficient, To Know More About Lists, Visit :  LIST COMPLETE THEORY





Tags

Post a Comment

1Comments
Post a Comment

Featured Highlighted Categories

You'll discover all of the most up-to-date bring innovative here.

Python List theory with List Programs
Get complete python lists theory and list basic and insane programs for your practice.
CBSE SAMPLE PAPERS
Get CBSE sample and question papers of last 7 years with answers to get best practice for your Board Exams
Python String theory and String Programs
Python strings complete theory with illustrations and practice programs for free