Python interview questions part 35

Python interview questions part 35

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

Total Questions: 20

1. Which of the following returns a string that represents the present working directory?

Correct Answer is : os.getcwd()

2. What does os.link() do?

Correct Answer is : create a hard link

3. Which of the following can be used to create a directory?

Correct Answer is : os.mkdir()

4. Which of the following can be used to create a symbolic link?

Correct Answer is : os.symlink()

5. Which function is called when the following code is executed? f = foo() format(f)

Correct Answer is : __str__()

6. Which of the following will print True? a = foo(2) b = foo(3) print(a < b)

Correct Answer is : class foo: def __init__(self, x): self.x = x def __lt__(self, other): if self.x < other.x: return True else: return False

7. Which function overloads the + operator?

Correct Answer is : __add__()

8. Which operator is overloaded by __invert__()?

Correct Answer is : ~

9. Which function overloads the == operator?

Correct Answer is : __eq__()

10. Which operator is overloaded by __lg__()?

Correct Answer is : none of the mentioned

11. Which function overloads the >> operator?

Correct Answer is : none of the mentioned

12. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?

Correct Answer is : __add__(), __str__()

13. Which operator is overloaded by the __or__() function?

Correct Answer is : |

14. Which function overloads the // operator?

Correct Answer is : __floordiv__()

15. The process of pickling in Python includes:

Correct Answer is : conversion of a Python object hierarchy into byte stream

16. To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.

Correct Answer is : dumps(), loads()

17. Pick the correct statement regarding pickle and marshal modules.

Correct Answer is : The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not do this

18. What is the output of the line of code shown below? pickle.HIGHEST_PROTOCOL

Correct Answer is : 4

19. Which of the codes shown below will result in an error? Given that: object = ‘a’

Correct Answer is : >>> pickle.dumps(object, 3, True)

20. Which of the following functions can be used to find the protocol version of the pickle module currently being used?

Correct Answer is : pickle.DEFAULT_PROTOCOL

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon