Python interview questions part 44

Python interview questions part 44

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

Total Questions: 20

1. Which of the following is not the correct syntax for creating a set?

Correct Answer is : set([[1,2],[3,4]])

2. What is the output of the following code? nums = set([1,1,2,3,3,3,4,4]) print(len(nums))

Correct Answer is : 4

3. What is the output of the following piece of code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")

Correct Answer is : 5 5 6 7 7 7

4. Which of the following statements is used to create an empty set?

Correct Answer is : set()

5. What is the output of the following piece of code when executed in the python shell? >>> a={5,4} >>> b={1,2,4,5} >>> a
Correct Answer is : TRUE


6. If a={5,6,7,8}, which of the following statements is false?

Correct Answer is : a[2]=45

7. If a={5,6,7}, what happens when a.add(5) is executed?

Correct Answer is : a={5,6,7}

8. What is the output of the following code? >>> a={4,5,6} >>> b={2,8,6} >>> a+b

Correct Answer is : Error as unsupported operand type for sets

9. What is the output of the following code? >>> a={4,5,6} >>> b={2,8,6} >>> a-b

Correct Answer is : {4,5}

10. What is the output of the following piece of code? >>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b

Correct Answer is : {5,6,10,11}

11. What is the output of the following code? >>> s={5,6} >>> s*3

Correct Answer is : Error as unsupported operand type for set data type

12. What is the output of the following piece of code? >>> a={5,6,7,8} >>> b={7,5,6,8} >>> a==b

Correct Answer is : TRUE

13. What is the output of the following piece of code? >>> a={3,4,5} >>> b={5,6,7} >>> a|b

Correct Answer is : {3,4,6,7}

14. Is the following piece of code valid? a={3,4,{7,5}} print(a[2][0])

Correct Answer is : Error, subsets aren’t allowed

15. Which of these about a frozenset is not true?

Correct Answer is : Mutable data type

16. What is the syntax of the following piece of code? >>> a=frozenset(set([5,6,7])) >>> a

Correct Answer is : frozenset({5,6,7})

17. Is the following piece of code valid? >>> a=frozenset([5,6,7]) >>> a >>> a.add(5)

Correct Answer is : No, frozen set is immutable

18. Set members must not be hashable. True or False?

Correct Answer is : FALSE

19. What is the output of the following piece of code? >>> a={3,4,5} >>> a.update([1,2,3]) >>> a

Correct Answer is : {1, 2, 3, 4, 5}

20. What is the output of the following piece of code when executed in the python shell? >>> a={1,2,3} >>> a.intersection_update({2,3,4,5}) >>> a

Correct Answer is : {2,3}

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon