Python

Python

Lists has 44 Questions
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

[2, 33, 222, 14]
Error
25
[25, 14, 222, 33, 2]
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?

Error
None
25
2
To shuffle the list(say list1) what function do we use?

list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
Suppose list1 is [1, 5, 9], what is sum(list1)?

1
9
15
Error
Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?

3
5
25
1
Suppose list1 is [2445,133,12454,123], what is max(list1)?

2445
133
12454
123
Suppose listExample is ['h','e','l','l','o'], what is len(listExample)?

5
4
None
Error
What is the output when we execute list("hello"?)?

['h', 'e', 'l', 'l', 'o']
['hello']
['llo']
['olleh']
What is the output when following code is executed ?
  1. >>>names = ['Amir', 'Bear', 'Charlton', 'Daman']
  2. >>>print names[-1][-1]

A
Daman
Error
n
What is the output when following code is executed ?
  1. names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
  2. names2 = names1
  3. names3 = names1[:]
  4. ?
  5. names2[0] = 'Alice'
  6. names3[1] = 'Bob'
  7. ?
  8. sum = 0
  9. for ls in (names1, names2, names3):
  10.     if ls[0] == 'Alice':
  11.         sum += 1
  12.     if ls[1] == 'Bob':
  13.         sum += 10
  14. ?
  15. print sum

11
12
21
22
Suppose list1 is [1, 3, 2], What is list1 * 2?

[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
What is the output when following code is executed ?
  1. >>>list1 = [11, 2, 23]
  2. >>>list2 = [11, 2, 2]
  3. >>>list1 < list2 is

True
False
Error
None
To add a new element to a list we use which command?

list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)
To insert 5 to the third position in list1, we use which command?

list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
To remove string "hello"? from list1, we use which command?

list1.remove("hello"?)
list1.remove(hello)
list1.removeAll("hello"?)
list1.removeOne("hello"?)
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)/?

0
1
4
2
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?

0
4
1
2
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?

[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[25, 20, 5, 5, 4, 3, 3, 1]
[3, 1, 25, 5, 20, 5, 4, 3]
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?

[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
[1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
[25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
[1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?

[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?

[3, 4, 5, 20, 5, 25, 1]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
What is the output when following code is executed ?
  1. >>>"Welcome to Python".split()

["Welcome"?, "to"?, "Python"?]
("Welcome"?, "to"?, "Python"?)
{"Welcome"?, "to"?, "Python"?}
"Welcome"?, "to"?, "Python"?
What is the output when following code is executed ?
  1. myList = [1, 5, 5, 5, 5, 1]
  2. max = myList[0]
  3. indexOfMax = 0
  4. for i in range(1, len(myList)):
  5.     if myList[i] > max:
  6.         max = myList[i]
  7.         indexOfMax = i
  8. ?
  9. >>>print(indexOfMax)

1
2
3
4
What is the output when following code is executed ?
  1. >>>list1 = [1, 3]
  2. >>>list2 = list1
  3. >>>list1[0] = 4
  4. >>>print(list2)

[1, 3]
[4, 3]
[1, 4]
[1, 3, 4]
What is the output when following code is executed ?
  1. def f(values):
  2.     values[0] = 44
  3. ?
  4. v = [1, 2, 3]
  5. f(v)
  6. print(v)

[1, 44]
[1, 2, 3, 44]
[44, 2, 3]
[1, 2, 3]
What is the output when following code is executed ?
  1. myList = [1, 2, 3, 4, 5, 6]
  2. for i in range(1, 6):
  3.     myList[i - 1] = myList[i]
  4. ?
  5. for i in range(0, 6): 
  6.     print(myList[i], end = " ")

2 3 4 5 6 1
6 1 2 3 4 5
2 3 4 5 6 6
1 1 2 3 4 5
What will be the output?
  1. def f(i, values = []):
  2.     values.append(i)
  3.     return values
  4. ?
  5. f(1)
  6. f(2)
  7. v = f(3)
  8. print(v)

[1] [2] [3]
[1] [1, 2] [1, 2, 3]
[1, 2, 3]
1 2 3
What will be the output?
  1. names1 = ['Amir', 'Bala', 'Chales']
  2. ?
  3. if 'amir' in names1:
  4.     print 1
  5. else:
  6.     print 2

None
1
2
Error
What will be the output?
  1. names1 = ['Amir', 'Bala', 'Charlie']
  2. names2 = [name.lower() for name in names1]
  3. ?
  4. print names2[2][0]

None
a
b
c
To which of the following the "in"? operator can be used to check if an item is in it?

Lists
Dictionary
Set
All of The Above
What will be the output?
  1. list1 = [1, 2, 3, 4]
  2. list2 = [5, 6, 7, 8]
  3. ?
  4. print len(list1 + list2)

2
4
5
8
What will be the output?
  1. def addItem(listParam):
  2.     listParam += [1]
  3. ?
  4. mylist = [1, 2, 3, 4]
  5. addItem(mylist)
  6. print len(mylist)

1
4
5
8
What will be the output?
  1. def example(L):
  2.     ''' (list) -> list
  3.     '''
  4.     i = 0
  5.     result = []
  6.     while i < len(L):
  7.         result.append(L[i])
  8.         i = i + 3
  9.     return result

Return a list containing every third item from L starting at index 0.
Return an empty list
Return a list containing every third index from L starting at index 0.
Return a list containing the items from L starting from index 0, omitting every third item.
What will be the output?
  1. veggies = ['carrot', 'broccoli', 'potato', 'asparagus']
  2. veggies.insert(veggies.index('broccoli'), 'celery')
  3. print(veggies)

['carrot', 'celery', 'broccoli', 'potato', 'asparagus'] Correct 1.00
['carrot', 'celery', 'potato', 'asparagus']
['carrot', 'broccoli', 'celery', 'potato', 'asparagus']
['celery', 'carrot', 'broccoli', 'potato', 'asparagus']
What will be the output?
  1. >>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
[[0, 1, 2], [1, 2, 3], [2, 3, 4]]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 1, 2, 3, 2, 3, 4]
How many elements are in m?
  1. m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

8
12
16
32
What will be the output?
  1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  2. ?
  3. v = values[0][0]
  4. for row in range(0, len(values)):
  5.     for column in range(0, len(values[row])):
  6.         if v < values[row][column]:
  7.             v = values[row][column]
  8. ?
  9. print(v)

3
5
6
33
What will be the output?
  1. values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
  2. ?
  3. for row in values:
  4.     row.sort()
  5.     for element in row:
  6.         print(element, end = " ")
  7.     print()

The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints on row 3 4 5 1 33 6 1 2
The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints two rows 1 3 4 5 followed by 1 2 6 33
What is the output?
  1. matrix = [[1, 2, 3, 4],
  2.        [4, 5, 6, 7],
  3.        [8, 9, 10, 11],
  4.        [12, 13, 14, 15]]
  5. ?
  6. for i in range(0, 4):
  7.     print(matrix[i][1], end = " ")

1 2 3 4
4 5 6 7
1 3 8 12
2 5 9 13
What will be the output?
  1. def m(list):
  2.     v = list[0]
  3.     for e in list:
  4.       if v < e: v = e
  5.     return v
  6. ?
  7. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  8. ?
  9. for row in values: 
  10.     print(m(row), end = " ")

3 33
1 1
5 6
5 33
What will be the output?
  1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  2. ?
  3. print(data[1][0][0])

1
2
4
5
What will be the output?
  1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
  2. ?
  3. def ttt(m):
  4.     v = m[0][0]
  5. ?
  6.     for row in m:
  7.         for element in row:
  8.            if v < element: v = element
  9. ?
  10.     return v
  11. ?
  12. print(ttt(data[0]))

1
2
4
5
What will be the output?
  1. points = [[1, 2], [3, 1.5], [0.5, 0.5]]
  2. points.sort()
  3. print(points)

[[1, 2], [3, 1.5], [0.5, 0.5]]
[[3, 1.5], [1, 2], [0.5, 0.5]]
[[0.5, 0.5], [1, 2], [3, 1.5]]
[[0.5, 0.5], [3, 1.5], [1, 2]]
What will be the output?
  1. points = [[1, 2], [3, 1.5], [0.5, 0.5]]
  2. points.sort()
  3. print(points)

[[1, 2], [3, 1.5], [0.5, 0.5]]
[[3, 1.5], [1, 2], [0.5, 0.5]]
[[0.5, 0.5], [1, 2], [3, 1.5]]
[[0.5, 0.5], [3, 1.5], [1, 2]]