Python, Django and Flask Technical Interview Questions
Looking forward to appear in Python, Django and Flask Interview, here are the key 100+ Java Interview Questions with Answers only for you including some of the tricky questions with answers.
Table of Contents
1. What do you like about Python and what you dislike about it?
Likes:
- Ease of interaction with other languages and platforms with 3rd party modules available in Python Package Index (PyPI). Also extensive support of libraries reduces the code writing effort significantly.
- Built in data structures and dynamic high level data typing allows faster implementation with less LoCs.
- Ease of learning and code redability because of its indentation oriented syntax.
Dislikes:
- Speed- being an interpreted language, it is not best suited for time-critical tasks.
- Multithreading - due to the Global Interpreter Lock.
2. What are major differences in Python 2.7 and 3.X
- Division operator
- Print function
- Unicode : In python 2.x implicit str type is ASCII, in 3.x its Unicode
- Xrange: is range in 3.x
- Error Handling: ‘as’ required in 3.x
- input() instead of raw_input()
- from future import division : allows to work 2.x as 3.x division operator
3. What is a Python Dictionary?
It is an unordered collection of items. A dictionary element has 2 components, a key and a value associated with it.
4. What are map(), filter() and reduce() functions in Python?
map(): It takes another function as a parameter along with a sequence of iterables and returns an output after applying the function to each iterable present in the sequence.
Syntax:
map(function, iterables)
filter(): The filter() function is used to create an output consisting of values for which the function returns true.
Syntax:
filter(function, iterables)
reduce(): The reduce(fun,seq) function is used to apply a particular function passed in its argument to all of the list elements mentioned in the sequence passed along. This function is defined in “functools” module.
5. What is monkey patching and is it ever a good idea?
Monkey patch refers to dynamic modifications of a class or module at run-time.
Common applications of monkey patching are:
- To extend or modify the behavior of third-party or built-in libraries or methods at runtime without touching the original code.
- During testing mock the behavior of libraries, modules, classes, or any objects.
- To quickly fix some issues if we do not have the time or resources to roll out a proper fix to the original software.
6. What is pickle?
It is used for serializing and de-serializing a Python object structure. Any object in python can be pickled so that it can be saved on disk. What pickle does is that it “serializes” the object first before writing it to a file. Pickling is a way to convert a python object (list, dict, etc.) into a character stream.
7. The basic structure of any Django app, what files are involved, and what are the components?
Above is the basic structure of any Dkango application.
8. How would you add the app in the command line?
python manage.py startapp [app name]
Use above command
9. What problem were you trying to solve when you used celery?
Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation but supports scheduling as well.
The execution units, called tasks, are executed concurrently on a single or more worker server using multiprocessing, Eventlet, or gevent. Tasks can execute asynchronously (in the background) or synchronously (wait until ready).
Celery allows you to execute tasks outside of your Python app so it doesn't block the normal execution of the program
10. How do you host your Django Application?
- Install necessary packages.
- Initial server setups.
- Preparing our Django app for production.
- Setting up gunicorn.
- Setting up nginx.
11. In Django, can you describe me the top of the basic comprehension needed to present in view of the template?
Django provides a convenient way to generate dynamic HTML pages by using its template system.
A template consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
12. Considering a file structure of a new application, what does it look like? How do you start a brand new project in Django?
django-admin startproject [project name]
Use above command