Name: ____________________ Roll No.
:___________________ Year/Sec:_________ SET-2
GEETHANJALI COLLEGE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PYTHON PROGRAMMING
[Link] of the following is correct code to display second largest element of list
‘L’? ( )
a. [Link]() b. [Link](reverse = True) c. print(sorted(L)[-1]) d. All of the
above
print(L[-1]) print(L[1])
[Link] at the following code and state which type of list operation it carries out?
( )
list = [‘t’,’e’,’c’,’h’,’t’,’i’,’p’,’n’,’o’,’n’,’w’]
for x in list:
print(x)
a. Repeating List b. Traversing List c. Slicing list d. Joining list
[Link] at the following code and state which type of list operation is being
carried out? ( )
list = [‘t’,’e’,’c’,’h’,’t’,’i’,’p’,’n’,’o’,’n’,’w’]
L = list*3
print(L)
a. Repeating List b. Traversing List c. Slicing list d. Joining list
[Link] at the following code and state which type of list operation is being
carried out? ( )
list = [‘t’,’e’,’c’,’h’,’t’,’i’,’p’,’n’,’o’,’n’,’w’]
Print(L[Link])
a. Repeating List [Link] List c. Slicing list d. Joining list
[Link] the output: ( )
L = [4,5,8,2,1,9]
[Link](4)
print(L)
a. [4,5,8,1,9] b. [4,5,8,2] c. [4,5,8,2,9] d. [5,8,2,1,9]
[Link] the output: ( )
L = [4,5,8,2,1,9]
[Link](4)
print(L)
a. [4,5,8,1,9] b. [4,5,8,2] c. [4,5,8,2,9] d. [5,8,2,1,9]
[Link] the output of given code? ( )
List1 = [2,3,4,5]
List2 = [6,7,8]
[Link](List2)
Print(List1)
a. [2,3,4,5,[6,7,8]] b. [[2,3,4,5],6,7,8] c. [2,3,4,5,6,7,8] d. [[2,3,4,5],[6,7,8]]
[Link] the output of given code? ( )
List1 = [2,3,4,5]
List2 = [6,7,8]
[Link](List2)
Print(List1)
a. [2,3,4,5,[6,7,8]] b. [[2,3,4,5],6,7,8] c. [2,3,4,5,6,7,8] d. [[2,3,4,5],[6,7,8]]
[Link] will be output of following code? ( )
list1 = [3,4,6,4,7, 8]
[Link](4)
print(list1)
a. [3,4,6,4,8] b. [3,6,4,7,8] c. [3,6,7,8] d. 3,4,6,7,8]
[Link] has created following list: ( )
list1 = [2,5,6,7]
Now he wants to add 12 at the end of list1. Help him to write correct code for it
a. [Link](len(list1), 12) b. [Link](12) c. [Link]([12]) d. All are
correct
11. Which type of error following code will produce? ( )
L = [3,6,87,12,6]
[Link]()
a. Index error b. Value error c. Logical error d. Runtime error
12. If no argument is passed to pop(), it removes ( )
a. First element of list b. Last element of list c. Produce error d. No element is
removed
13. To sort a list ‘exp’ in decreasing order we can write ( )
a. [Link]() b. [Link](reverse = True) c. [Link](reverse = False) d.
[Link](asc = True)
14. The sale of techtipnow for this week is stored in a list1 as
[25,45,23,52,61,40,36]. Manager of ( )
techtipnow want to find the average sale of week. Help him to write code for so.
a. sum(list1)/count(list1) b. avg(list1) c. sum(list1)/len(list1) d.
total(list1)/count(list1)
15. predict the output for following code: ( )
list1 = [‘mango’,’orange’,’grapes’,’banana’,’guava’]
a. banana b. grapes c. guava d. orange
[Link] of the following is NOT true about List? ( )
a. List is value mutable b. List can store heterogeneous items c. List is size
immutable d. List is ordered collection of items
[Link] correct statement ( )
i. Duplicate items are not allowed to store in List
ii. We can use both index and negative index of list items to access it.
a. i true, ii false b. i false, ii true c. both are true d. both are false
[Link] find the total no of elements in list we can use ________ method ( )
a. length() b. len() c. count() d. find()
[Link] remove an item from list we can use (
)
a. pop() b. remove() c. del() d. both a and b e. all of the above
[Link] will be output of given code? ( )
L =[23,34,45,12,32]
Print(L[-3])
a. 45 b. 34 c. Error d. 12
[Link] the output of ( )
L = [‘s’,’a’,’n’,’j’]
print(L[4])
a. s b. j c. index error d. sanj
[Link] the output of given code: ( )
L = [3,5,2]
print(L*2)
a. [ 6, 10, 4] b. [3, 5, 2, 3, 5, 2] c. [9, 25, 4] d. None
23.____ method adds a new item/list as a single element at the end of list ( )
a. extend() b. append() c. insert() d. list()
24._________ method add an element at a particular index in the list. ( )
a. extend() b. append() c. insert() d. list()
[Link] delete an element using its index no we can use ( )
a. pop() b. remove() c. delete() d. find()
[Link] delete an element using its value _________ can be used. ( )
a. pop() b. remove() c. del() d. list()
27._______ method adds each element of list passed as argument at the end of
the given list. ( )
a. extend( ) b. append() c. insert() d. list()
[Link] the correct statement to display the last element of list ‘L’?
( )
a. L[-1] b. L[len(L)-1] c. L[len(L)] d. Both a and b e. Both a and c
[Link] the correct statement to display the first element of list ‘L’?
( )
a. L[0] b. L[1] c. L[-len(L)] d. L[-len(L)-1]
[Link] of the following is correct code to display largest element of list ‘L’?
( )
a. [Link]() print(L[-1]) b. [Link](reverse = True) print(L[0]) c. max(L) d. All of the
above
[Link] the command to insert a number 12 at 4 ( )
position of list named list1.
a. [Link](4,12) b. [Link](3,12) c. [Link](12,4) d. [Link](12,3)
[Link] will be correct output when given code will be executed? ( )
a1 = [2,3]
a2 = [3,5,7]
[Link](a1)
print(a1 in a2)
a. True b. False c. Error d. [2,3]
[Link] the output: ( )
exp = [2,3,4,5,6,4,8,2,4,10]
[Link](4)
c = [Link](4)
print(c)
a. error b. 1 c. 2 d. 9
[Link] check whether an item is present in list or not, we can use ( )
a. not [Link] c. in d. or
[Link] get the index value of an item of list1, we can write ( )
a. [Link](value) b. index(list1, value) c. index(value, list1) d. list1[value].index
[Link] a given list L1 as [[2,3,[4,5],6,7]], if you execute following command ( )
print(sum(L1))
will produce
a. 27 [Link] output c. error d. 0
[Link] stored attendance of her class for this week in list ‘atd’ as given
below: ( )
atd = [32,37,23,28,30,40,31]
principal ask her to fi nd the median of given nos. what code she write in python to get
this?
a. print(sum(atd)/len(atd)) b. print(sum(atd)/count(atd))
c. [Link]() d. [Link]()
print(atd[len(atd)//2]) print(atd[(len(atd)//2)+1]
[Link] created a list ‘L1’ with duplicate items. Ishaan suggested him to modify
this list so it does notcontains any duplicate element i.e. all elements occurring
multiple times in the list should appear onlyonce. Helm him to do so. ( )
a. R=[]for i in range(L1):if i not in R:[Link](i) b. R = list(set(L1)) c. Both d. None
[Link] the output of given code: ( )
L = [1,2,3]
print(L + L*L)
a. [1,2,3,1,4,9] b. [1,6,12] c. [1,2,3,1,2,3,1,2,3] d. Error
[Link] wrote following code to fi nd the length of a list : ( )
m = [12, ‘techtipnow’,[10,11],12.08,’x’,True, 30]
print(len(m))
what output you can predict for this code?
a. Error b. 17 c. 8 d. 7
[Link] new list by extracting items from existing list is called ( )
a. Traversing b. Copying c. Slicing d. Extending
[Link] display all items of list1 in reverse order we can write ( )
a. List[::-1] b. [Link]() c. Both d. None
[Link] display fi rst 3 items for given list ( )
K = [3,4,6,7,2,1,8,9,4,6]
we can write
a. K[:3] b. K[:-7] c. K[-10:3] d. All of the above
[Link] given list ( )
L=[4,5,6,7,2,3,1,5,3,6]
if we try to slice L[6:13], than what will be the output?
a. [1, 5, 3, 6] b. [1, 5, 3, 6,0,0,0] c. Index Error d. [ ] (No Output)
[Link] list1 is [‘a’,’e’,’i’,’o’,’u’], than what will be list1[:-1]? ( )
a. [‘a’,’e’,’i’,’o’,’u’] b. [‘a’,’e’,’i’,’o’] c. [‘u’,’o’,’i’,’e’,’a’] d. [ ]
[Link] the correct statement:
( )
i. Slicing cannot be done on a variable
ii. We cannot use slices to modify one or more list items with one or more other items.
a. i true, ii falsem b. I false, ii true c. Both true d. Both false
[Link] the output of given code ( )
K = [3,4,6,7,2,1,8,9,4,6] print(K[3:-3])
a. [7,2,1,8] b. [7,2,1,8,9] c. [8,1,2,7] d. [7]
[Link] a given list1[3,4,6,7,2,1,8,9,4,6], what code we can write to display its
alternate items frombeginning? ( )
a. List1[:2]Discover employer of record services Solution. Find Related Results Now
Open
b. List1[::2] c. List1[0:len(List1):2] d. All of the above
[Link] Sir has made following list:
( )
L1 = [74, 33, 22, 19, 41, 65]
He asked his student to write code to delete last element of list L1. Help them to select
correct code.
a. [Link](len(L1)-1) b. [Link](-1) c. del L1[-1] d. All are correct
[Link] to the previous question 49, Sir wanted to add a new number 66
before 19 in list L1. He askedRaheem to identify the position of 19 and insert that.
What code Raheem should tell him? ( )
a. [Link]([Link](19), 66) b. [Link]([Link](19), 66) c. [Link](66,
[Link](19)) d. [Link](66, [Link](19))