Python interview questions part 27

Python interview questions part 27

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?

Correct Answer is : 2

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

Correct Answer is : 2

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

Correct Answer is : [3, 1, 25, 5, 20, 5, 4, 3].

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

Correct Answer is : [3, 4, 5, 20, 5, 25, 1, 3, 34, 5].

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

Correct Answer is : [3, 5, 20, 5, 25, 1, 3].

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

Correct Answer is : [3, 4, 5, 20, 5, 25, 1].

7. What is the output when the following code is executed ? >>>"Welcome to Python".split()

Correct Answer is : [“Welcome”, “to”, “Python”].

8. What is the output when following code is executed ? >>>list("a#b#c#d".split('#'))

Correct Answer is : [‘a’, ‘b’, ‘c’, ‘d’].

9. What is the output when following code is executed ? myList = [1, 5, 5, 5, 5, 1]max = myList[0]indexOfMax = 0for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i >>>print(indexOfMax)

Correct Answer is : 1

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

Correct Answer is : 2 3 4 5 6 6

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

Correct Answer is : [4, 3].

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

Correct Answer is : [44, 2, 3].

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

Correct Answer is : [1, 2, 3].

14. What will be the output? names1 = ['Amir', 'Bala', 'Chales'] if 'amir' in names1: print(1)else: print(2)

Correct Answer is : 2

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

Correct Answer is : c

16. What will be the output? numbers = [1, 2, 3, 4] numbers.append([5,6,7,8]) print(len(numbers))

Correct Answer is : 5

17. To which of the following the “in” operator can be used to check if an item is in it?

Correct Answer is : All of the mentioned

18. What will be the output? list1 = [1, 2, 3, 4]list2 = [5, 6, 7, 8] print(len(list1 + list2))

Correct Answer is : 8

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

Correct Answer is : 5

20. What will be the output? def increment_items(L, increment): i = 0 while i < len(L): L[i] = L[i] + increment i = i + 1 values = [1, 2, 3]print(increment_items(values, 2))print(values)

Correct Answer is : None

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon