Open In App

Output of Python program | Set 6 (Lists)

Prerequisite – Lists in Python Predict the output of the following Python programs. These question set will make you conversant with List Concepts in Python programming language.




list1 = ['physics', 'chemistry', 1997, 2000]
 
list2 = [1, 2, 3, 4, 5, 6, 7 ]
  
print "list1[0]: ", list1[0]        #statement 1
print "list1[0]: ", list1[-2]       #statement 2
print "list1[-2]: ", list1[1:]      #statement 3
print "list2[1:5]: ", list2[1:5]    #statement 4

list1[0]:  physics
list1[0]:  1997
list1[-2]:  ['chemistry', 1997, 2000]
list2[1:5]:  [2, 3, 4, 5]




list1 = ['physics', 'chemistry', 1997, 2000]
 
print "list1[1][1]: ", list1[1][1] #statement 1
 
print "list1[1][-1]: ", list1[1][-1] #statement 2

list1[1][1]:  h
list1[1][-1]:  y




list1 = [1998, 2002, 1997, 2000]
list2 = [2014, 2016, 1996, 2009]
 
print "list1 + list 2 = : ", list1 + list2   #statement 1
 
print "list1 * 2 = : ", list1 * 2  #statement 2

list1 + list 2 = :  [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009]
list1 * 2 = :  [1998, 2002, 1997, 2000, 1998, 2002, 1997, 2000]




list1 = range(100, 110) #statement 1
print "index of element 105 is : ", list1.index(105#statement 2

index of element 105 is :  5




list1 = [1, 2, 3, 4, 5]
list2 = list1
 
list2[0] = 0;
 
print "list1= : ", list1 #statement 2

list1= :  [0, 2, 3, 4, 5]

Article Tags :