Saturday, October 5, 2019

Top 10 Python interview questions that you must know



Python is by far the most popular programming language available today. Python developers have the highest demand in the industry. If you possess Python skills and are looking for a job, here are top interview questions you need to know.

1. Explain PYTHONPATH variable?
PYTHONPATH is an environment variable. It has a value that is a string with a list of directories that Python should add to the sys.path directory list. The variable is mainly used for developing some code that you want to import from Python. You can manually set PYTHONPATH, but usually, the Python installer will preset it.

2. Why Python is single threaded?
Python has thread packages, but in some versions of Python the global interpreter lock ensures that at any given point in time only one thread can execute (it holds the lock). Single thread nature increases the speed of applications and eases the integration of C libraries.

3. What are try, raise, and finally?
These keywords are used during exception handling. You can put risky code under a try block or use the raise statement to explicitly raise an error. The practice finally puts code block that you want to use.

4. What if you do not handle an error in the except block?
If you don’t do this, the program terminates. Then, it sends an execution trace to sys.stderr.

5. What's the function of recursion?
The recursion ensures that you put less efforts. You no longer have to write the long code. You can write a smaller code by loops. Recursion also makes it easier to understand the code.

6. What is init?
It is a method or constructor used to automatically call to allocate memory when new object or instance of a class is created. All classes typically have the init method.

7. What is lambda?
Lambda is an anonymous function that can have multiple parameters but a single statement.

8. What are iterators?
Iterators are objects used to transverse through or iterated upon.

9. How to write comments in Python?
Python comments start with # character. Mostly commenting is done using docstring (strings closed within triple quotes).

10. What is pickling and unpickling?
Pickle module accepts any Python object and converts it into string representation and dumps it into a file using dump function, this process is called pickling.

No comments:

Post a Comment

Google’s Keep note-taking app is getting a new feature courtesy of Android 14 that’s a huge time-saver, even if Samsung got there first

  There’s a certain balance that needs to be achieved with lock screen functionality. You can’t give away too much because of, well, securit...