Saturday, August 3, 2019

Python Inteview Questions And Answers





Q  What is the starting point of Python code execution?
Answer: As Python is an interpreter, it starts reading the code from the source file and starts executing them.
However, if you want to start from the main function, you should have the following special variable set in your source file as:
if__name__== “__main__
main()

Q  Name some of the important modules that are available in Python.
Answer: Networking, Mathematics, Cryptographic services, Internet data handling, and Multi-threading modules are prominent modules. Apart from these, there are several other modules that are available in the Python developer community.

Q Which module(s) of Python can be used to measure the performance of your application code?
Answer: Time module can be used to calculate the time at different stages of your application and use the Logging module to log data to a file system in any preferred format.

Q How do you launch sub-processes within the main process of a Python application?
Answer: Python has a built-in module called sub-process. You can import this module and either use run() or Popen() function calls to launch a sub-process and get the control of its return code.





Q As Python is more suitable for the server-side application, it is very important to have threading implemented in your server code. How can you achieve that in Python?
Answer: We should use the threading module to implement, control and destroy threads for parallel execution of the server code. Locks and Semaphores are available as synchronization objects to manage data between different threads.
Q  Do we need to call the explicit methods to destroy the memory allocated in Python?
Answer: Garbage collection is an in-built feature in Python which takes care of allocating and de-allocating memory. This is very similar to the feature in Java.
Hence, there are very fewer chances of memory leaks in your application code.

Q Does the same Python code work on multiple platforms without any changes?
Answer: Yes. As long as you have the Python environment on your target platform (Linux, Windows, Mac), you can run the same code.




Q  How can you create a GUI based application in Python for client-side functionality?
Answer: Python along with standard library Tkinter can be used to create GUI based applications. Tkinter library supports various widgets which can create and handle events which are widget specific.

Q  What are the different environment variables identified by Python?
Answer:
PYTHONPATH: This environment variable helps the interpreter as to where to locate the module files imported in the program.
PYTHONSTARTUP: This environment variable contains the path of the Initialization file containing source code.
PYTHONCASEOK: This variable is used to find the first case-insensitive match in the import statement

Q  What is Python Tuples and how is it different from Lists?
Answer: Tuples is basically a sequence of elements which are separated by commas and are enclosed in parenthesis.
Lists whereas is a sequence of elements which are separated by commas and are enclosed in brackets. Also, Tuples cannot be updated whereas, in lists, elements can be updated along with their sizes.

Q What does ‘#’ symbol do in Python?
Answer: ‘#’ is used to comment out everything that comes after on the line.
Example:
print (“I am a beginner in Python”)
#print (“I am a beginner in Python”)
Output:
I am a beginner in Python





Q What does stringVar.strip() does?
Answer: This is one of the string methods which removes leading/trailing white space.


No comments:

Post a Comment

Which Python course is best for beginners?

Level Up Your Python Prowess: Newbie Ninjas: Don't fret, little grasshoppers! Courses like "Learn Python 3" on Codecade...