JOBSEEKERS
Login
Sign Up
Jobseeker
Employer
Staffing Firm
Direct Firm
Python interview questions part 45
Python interview questions part 45
Back
Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What is the output for the following piece of code? >>> a={1,2,3} >>> b=a >>> b.remove(3) >>> a
A. {1,2,3}
B. Error, copying of sets isn’t allowed
C. {1,2}
D. Error, invalid syntax for remove
Show Correct Answer
Correct Answer is :
{1,2}
2. What is the output of the following piece of code? >>> a={1,2,3} >>> b=a.copy() >>> b.add(4) >>> a
A. {1,2,3}
B. Error, invalid syntax for add
C. {1,2,3,4}
D. Error, copying of sets isn’t allowed
Show Correct Answer
Correct Answer is :
{1,2,3}
3. What is the output of the following code? >>> a={1,2,3} >>> b=a.add(4) >>> b
A. None
B. {1,2,3,4}
C. {1,2,3}
D. Nothing is printed
Show Correct Answer
Correct Answer is :
Nothing is printed
4. What is the output of the following code? >>> a={1,2,3} >>> b=frozenset([3,4,5]) >>> a-b
A. {1,2}
B. Error as difference between a set and frozenset can’t be found out
C. Error as unsupported operand type for set data type
D. frozenset({1,2})
Show Correct Answer
Correct Answer is :
{1,2}
5. What is the output of the following piece of code? >>> a={5,6,7} >>> sum(a,5)
A. 5
B. 23
C. 18
D. Invalid syntax for sum method, too many arguments
Show Correct Answer
Correct Answer is :
23
6. What is the output of the following code? >>> a={1,2,3} >>> {x*2 for x in a|{4,5}}
A. {2,4,6}
B. Error, set comprehensions aren’t allowed
C. {8, 2, 10, 4, 6}
D. {8,10}
Show Correct Answer
Correct Answer is :
{8, 2, 10, 4, 6}
7. What is the output of the following piece of code? >>> a={5,6,7,8} >>> b={7,8,9,10} >>> len(a+b)
A. 8
B. Error, unsupported operand ‘+’ for sets
C. 6
D. Nothing is displayed
Show Correct Answer
Correct Answer is :
Error, unsupported operand ‘+’ for sets
8. What is the output of the following piece of code? a={1,2,3} b={1,2,3} c=a.issubset(b) print(c)
A. TRUE
B. Error, no method called issubset() exists
C. Syntax error for issubset() method
D. FALSE
Show Correct Answer
Correct Answer is :
TRUE
9. Is the following piece of code valid? a={1,2,3} b={1,2,3,4} c=a.issuperset(b) print(c)
A. FALSE
B. TRUE
C. Syntax error for issuperset() method
D. Error, no method called issuperset() exists
Show Correct Answer
Correct Answer is :
FALSE
10. What is the output of the code shown? s=set() type(s)
A. <’set’>
B.
C. set
D. class set
Show Correct Answer
Correct Answer is :
11. The line of code shown below results in an error. State whether this statement is true or false. s={2, 3, 4, [5, 6]}
A. TRUE
B. FALSE
C.
D.
Show Correct Answer
Correct Answer is :
TRUE
12. Set makes use of __________ Dictionary makes use of ____________
A. keys, keys
B. key values, keys
C. keys, key values
D. key values, key values
Show Correct Answer
Correct Answer is :
keys, key values
13. Which of the following lines of code will result in an error?
A. s={abs}
B. s={4, ‘abc’, (1,2)}
C. s={2, 2.2, 3, ‘xyz’}
D. s={san}
Show Correct Answer
Correct Answer is :
s={san}
14. What is the output of the code shown below? s={2, 5, 6, 6, 7} s
A. {2, 5, 7}
B. {2, 5, 6, 7}
C. {2, 5, 6, 6, 7}
D. Error
Show Correct Answer
Correct Answer is :
{2, 5, 6, 7}
15. Input order is preserved in sets. State whether this statement is true or false.
A. TRUE
B. FALSE
C.
D.
Show Correct Answer
Correct Answer is :
FALSE
16. Write a list comprehension for number and its cube for: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
A. [x**3 for x in l]
B. [x^3 for x in l]
C. [x**3 in l]
D. [x^3 in l]
Show Correct Answer
Correct Answer is :
[x**3 for x in l]
17. What is the output of the code shown below? s={1, 2, 3} s.update(4) s
A. {1, 2, 3, 4}
B. {1, 2, 4, 3}
C. {4, 1, 2, 3}
D. Error
Show Correct Answer
Correct Answer is :
Error
18. Which of the following functions cannot be used on heterogeneous sets?
A. pop
B. remove
C. update
D. sum
Show Correct Answer
Correct Answer is :
sum
19. What is the output of the code shown below? s={4>3, 0, 3-3} all(s) any(s)
A. TRUE
B. FALSE
C. TRUE
D. FALSE
Show Correct Answer
Correct Answer is :
FALSE
20. Which of the following functions will return the symmetric difference between two sets, x and y?
A. x | y
B. x ^ y
C. x & y
D. x – y
Show Correct Answer
Correct Answer is :
x & y
Similar Interview Questions
Search for latest jobs
Find Jobs