Python Interview Questions


Q11: How to manage the memory in Python?

Ans: There are a few ways to manage the memory in Python.

  • For Memory management, there is a feature called Python private heap space. Here, in a private heap, almost all the Python objects and data structures are situated. No programmer can access this private heap. Instead of that, the python interpreter help with this.
  • The Python’s memory manager is responsible for allocating the objects in the heap space. There are a few tools that can aid the programmer in code. And, they are provided by the core API.
  • The inbuilt garbage collector in Python recycles the memory that is not being used. In this way, it provides memory to the heap space.

Q12: What makes NumPy and SciPy different from one another?

Ans: In Python, two of the most essential libraries are NumPy and SciPy. They have contradicting operations. Furthermore, these libraries offer several functions for the users. Before working with these libraries, you must know the basics of python.

NumPy is used for Numerical Python. And, SciPy is advantageous for Scientific Python language is utilized for these functions. NumPy is famous for manipulation the elements of numerical array data. SciPy provides multiple sub-packages, so it can be called a collection of functions. These functions involve clustering, processing of images, integration, and much more. SciPy has all the numerical codes. NumPy shows compatibility, so it retains all features supported by the antecedent. For computing scientific data with python, you must have both of them.

Q13: How to use NumPy/SciPy to create 3D plots/visualizations?

Ans: For visualizing data, we got some options within our reach. You can figure out these features by making heatmaps, contour plots, and a 3D plot. In 3D plots, we can provide more intensity for the viewers. So, if you want to provide a perfect sense of these intensity values, you can plot the data in 3D. Resembling the 2D plotting, 3D graphics is out of the range of NumPy and SciPy. Yet, like 2D plots, packages are available that integrate with NumPy. For straightforward 3D plotting in the mplot3d subpackage, Matplotlib can be used. In addition to that, Mayavi helps to achieve high-quality 3D visualization features.

Q14: Why Flask is useful?

Ans: As mentioned above, it is a web microframework. It is somewhat based on Werkzeug, Jinja2 with better options. That’s why it depends on both of them. In other words, if you have it at your disposal, you don’t really have to depend on external libraries. Because of that, it is a light framework light with minimum security bugs.

Mainly, a session gives you the choice to memorize information from one request to the other one. Here, you can modify and view the section as it utilizes a signed cookie. For modifications, a secret is required. This key is the Flask.secret_key.

Q15: Which one is better: Django or Flask?

Ans: Mapping the URL’s or addresses typed in the web browsers to functions is made possible by these two.

If we draw a comparison between these two, Flask is way easier than Django. That is the reason why Flask needs you to specify the details. In Django, you don’t have to indulge in much work as it does the work for you. Django contains prewritten codes that you only need to analyze. In contrast to it, when you use Flask, you must generate the code. Thus, it becomes easier for the user to comprehend the code. We can conclude that both comes with benefits and drawbacks.