[DECLARATION AND INTIALIZATION OF LIST]
COMPUTER SCIENCE(083)
CLASS: XII
LIST IN PYTHON
PART-1
What is List?
How we declare a List?
How we initialize a List?
Different methods of initializing list.
WHAT IS LIST:
A list is a collection of values or an ordered sequence of values.
Values in the list can be
Elements of a list enclosed in a square brackets [ ], separated by
commas (,) .
Syntax:
list_name= [value1, value2,……..,valueN]
Example:
No_list = [ 10, 20, 30, 40, 50 ]
HOW TO CREATE AND INITIALIZE LIST
Method 1: If list is declare empty.
list1=[ ]
Method 2: Initialize list with value:
If we want to store the numbers in a list.
list2= [10, 20, 30, 40, 50]
If we want to store the words or string in a list.
list3= [“Mango”, “Apple”,”Grapes”,”Oranges”]
HOW TO CREATE AND INITIALIZE LIST
If we want to store the characters in a list.
list4= [‘A’,’E’,’I’,’O’,’U’]
If we want to store the mixed information in a list.
list4= [“Kapil”, 13,”Class-IX”, 40]
TO DISPLAY THE LIST
Example:
list2= [10, 20, 30, 40, 50]
print(list2)
----------------Output-------------
[10, 20, 30, 40, 50]
Example:
list3= [“Mango”, “Apple”,”Grapes”,”Oranges”]
print(list3)
----------------Output-------------
[‘Mango’, ‘Apple’, ’Grapes’, ’Oranges’]
HOW TO CREATE AND INITIALIZE THE
LIST USING LIST() CONSTRUCTOR
Syntax:
list_name=list(sequence or string)
Example:
list1=list(‘Computer’)
print(list1)
----------output----------
[‘C’,’o’,’m’,’p’,’u’,’t’,’e’,’r’]
If we want to store the characters in a list.
list4= list((‘A’,’E’,’I’,’O’,’U’))
---------Output----------
[‘A’, ‘E’,’I’,’O’,’U’]
HOW TO CREATE AND INITIALIZE THE
LIST USING LIST() CONSTRUCTOR
Example:
If we want to store the mixed information in a list.
list4= list((“Kapil”, 13,”Class-IX”, 40))
----------------Output-------------
[‘Kapil’, 13,’Class-IX’, 40]
Example: If we want to store the numbers in a list.
List_=list((10, 20, 30, 40, 50))
----------------Output-------------
[10, 20, 30, 40, 50]
HOW USER ENTER THE VALUES IN A LIST
AT RUN TIME
Using input() function how we can enter the number inside the list.
If we want to enter number 1,2,3,4,5,6,7,8,9 using keyboard at the
run time
Example:
no=list(input(“Enter the no”))
print(no)
-----------Output-------------
[‘1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’]
These numbers are store in a character format as these numbers
are display in ‘1’ format.
We can use eval( ) method, which identifies the data type and
evaluate them automatically.
Example:
no=eval(input(“Enter the no:”))
print(no)
-------Input-----------
Enter the no: [1,2,3,4,5,6,7,8,9]
-----------Output-------------
[1,2,3,4,5,6,7,8,9]
-------Input-----------
Enter the no: 1,2,3,4,5,6,7,8,9
-----------Output-------------
(1,2,3,4,5,6,7,8,9)
If you enter the number with square
brackets it will create List
If you enter the number without
square brackets it will create tuple

LIST IN PYTHON

  • 1.
    [DECLARATION AND INTIALIZATIONOF LIST] COMPUTER SCIENCE(083) CLASS: XII LIST IN PYTHON PART-1
  • 2.
    What is List? Howwe declare a List? How we initialize a List? Different methods of initializing list.
  • 3.
    WHAT IS LIST: Alist is a collection of values or an ordered sequence of values. Values in the list can be Elements of a list enclosed in a square brackets [ ], separated by commas (,) . Syntax: list_name= [value1, value2,……..,valueN] Example: No_list = [ 10, 20, 30, 40, 50 ]
  • 4.
    HOW TO CREATEAND INITIALIZE LIST Method 1: If list is declare empty. list1=[ ] Method 2: Initialize list with value: If we want to store the numbers in a list. list2= [10, 20, 30, 40, 50] If we want to store the words or string in a list. list3= [“Mango”, “Apple”,”Grapes”,”Oranges”]
  • 5.
    HOW TO CREATEAND INITIALIZE LIST If we want to store the characters in a list. list4= [‘A’,’E’,’I’,’O’,’U’] If we want to store the mixed information in a list. list4= [“Kapil”, 13,”Class-IX”, 40]
  • 6.
    TO DISPLAY THELIST Example: list2= [10, 20, 30, 40, 50] print(list2) ----------------Output------------- [10, 20, 30, 40, 50] Example: list3= [“Mango”, “Apple”,”Grapes”,”Oranges”] print(list3) ----------------Output------------- [‘Mango’, ‘Apple’, ’Grapes’, ’Oranges’]
  • 7.
    HOW TO CREATEAND INITIALIZE THE LIST USING LIST() CONSTRUCTOR Syntax: list_name=list(sequence or string) Example: list1=list(‘Computer’) print(list1) ----------output---------- [‘C’,’o’,’m’,’p’,’u’,’t’,’e’,’r’] If we want to store the characters in a list. list4= list((‘A’,’E’,’I’,’O’,’U’)) ---------Output---------- [‘A’, ‘E’,’I’,’O’,’U’]
  • 8.
    HOW TO CREATEAND INITIALIZE THE LIST USING LIST() CONSTRUCTOR Example: If we want to store the mixed information in a list. list4= list((“Kapil”, 13,”Class-IX”, 40)) ----------------Output------------- [‘Kapil’, 13,’Class-IX’, 40] Example: If we want to store the numbers in a list. List_=list((10, 20, 30, 40, 50)) ----------------Output------------- [10, 20, 30, 40, 50]
  • 9.
    HOW USER ENTERTHE VALUES IN A LIST AT RUN TIME Using input() function how we can enter the number inside the list. If we want to enter number 1,2,3,4,5,6,7,8,9 using keyboard at the run time Example: no=list(input(“Enter the no”)) print(no) -----------Output------------- [‘1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’] These numbers are store in a character format as these numbers are display in ‘1’ format.
  • 10.
    We can useeval( ) method, which identifies the data type and evaluate them automatically. Example: no=eval(input(“Enter the no:”)) print(no) -------Input----------- Enter the no: [1,2,3,4,5,6,7,8,9] -----------Output------------- [1,2,3,4,5,6,7,8,9] -------Input----------- Enter the no: 1,2,3,4,5,6,7,8,9 -----------Output------------- (1,2,3,4,5,6,7,8,9) If you enter the number with square brackets it will create List If you enter the number without square brackets it will create tuple