| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

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

Total Questions: 20

1. What is the output of the snippet of code shown below? z=set('abc$de') 'a' in z

Correct Answer is : TRUE

2. What is the output of the code shown below? z=set('abc') z.add('san') z.update(set(['p', 'q'])) z

Correct Answer is : {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}

3. What is the output of the code shown below? s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])

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

4. What is the output of the code shown below? for x in set('pqr'): print(x*2)

Correct Answer is : pp

5. What is the output of the following code? {a**2 for a in range(4)}

Correct Answer is : {0, 1, 4, 9}

6. What is the output of each of the functions shown below? {x for x in 'abc'} {x*3 for x in 'abc'}

Correct Answer is : {‘a’, ‘b’, ‘c’}

7. The output of the line of code shown below is: class<’set’>. State whether this statement is true or false. type({})

Correct Answer is : FALSE

8. The output of the code shown below is: a=[1, 4, 3, 5, 2] b=[3, 1, 5, 2, 4] a==b set(a)==set(b)

Correct Answer is : FALSE

9. What is the output of the code shown below? l=[1, 2, 4, 5, 2, 'xy', 4] set(l) l

Correct Answer is : {1, 2, 4, 5, ‘xy’}

10. What is the output of the code shown below? s1={3, 4} s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1 print(s3)

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

11. The ____________ function removes the first element of a set and the last element of a list.

Correct Answer is : pop

12. The difference between the functions discard and remove is that:

Correct Answer is : Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element

13. What is the output of the code shown below? s1={1, 2, 3} s2={3, 4, 5, 6} s1.difference(s2) s2.difference(s1)

Correct Answer is : {1, 2}

14. What is the output of the following code? s1={1, 2, 3} s2={4, 5, 6} s1.isdisjoint(s2) s2.isdisjoint(s1)

Correct Answer is : TRUE

15. If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:

Correct Answer is : s2.issuperset(s1)

16. What is the output of this code? s1={1, 2, 3, 8} s2={3, 4, 5, 6} s1|s2 s1.union(s2)

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

17. What is the output of the code shown below? a=set('abc') b=set('def') b.intersection_update(a) a b

Correct Answer is : {‘b’, ‘c’, ‘a’}

18. What is the output of the line of code shown below, if s1= {1, 2, 3}? s1.issubset(s1)

Correct Answer is : TRUE

19. What is the output of the snippet of code shown below? x=set('abcde') y=set('xyzbd') x.difference_update(y) x y

Correct Answer is : {‘a’, ‘c’, ‘e’}

20. Which type of copy is shown in this code? l1=[[10, 20], [30, 40], [50, 60]] ls=list(l1) ls [[10, 20], [30, 40], [50, 60]]

Correct Answer is : Shallow copy