0% found this document useful (0 votes)
4 views

Interview Questions

The document contains a comprehensive list of Python and Django interview questions, covering topics such as context managers, decorators, differences between data structures, Django architecture, REST APIs, and SQL commands. It also includes specific questions about user authentication, middleware, caching strategies, and various Django features. Additionally, the document addresses practical coding tasks and theoretical concepts relevant to Python and Django development.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Interview Questions

The document contains a comprehensive list of Python and Django interview questions, covering topics such as context managers, decorators, differences between data structures, Django architecture, REST APIs, and SQL commands. It also includes specific questions about user authentication, middleware, caching strategies, and various Django features. Additionally, the document addresses practical coding tasks and theoretical concepts relevant to Python and Django development.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

PYTHON INTERVIEW QUESTIONS

1.what is context manager


2.where did you use decorators in project
3.what is the diff between list and dictionary
4.where we use list in real time
5.diff between Flask and Django
6.can you please write model and views for user interface
7.explain the flow in Django
8.what is the use of templates
9.what are the tokens did u used in your project
10.why we use sessions
11.did you create any custom middlewares?
12.if we have multiple databases,the we have to connect with one customized DB.how u will do
that?
13.what is decorator?
14.what is generator?diff b/w iterator and generator?
15.how memory management is handled in python?
16.what is init?
17.explain local and global variables?
18.what are the topics in oops?
19.what is inheritance
20.what is mixin?
21.how you can debug your code?
21.explain project level files?
22.push and pull diff?
23.why do we use Git?
24.Git stash?
25.diff between git and github?
26.explain polymorphism?
27.what is CSRF Token?
28.what is authentication and authorization?
29.what is ORM
30.find even number or odd number in list
31.access last element in list
32.find doubles of element using lambda
33.reverse array in pandas
34. REST API
35. what are the calls in REST API
36. some GIT commands
37. challenges
38. can u explain agile methodology
39. palindrome
40 count characters in string
41. Lambda expression
42. what are the user authentication methods
43. explain about project
44. diff between push and commit
45.scenario based sql questions given
46.write a python code for login page

Q.where you used Numpy in your project?


to plot the cost effectiveness of scenarios.matplotlib used ...histogram and bar,pie
x y axis
Q.status codes?
100-199------------------informational responses
200-299------------------successful responses 200 ok
300-399------------------Redirectional messages 301 Permanent Redirect. 302 Temporary
Redirect.
400-499-----------------client error responses 400 bad request 404 - Not Found. 410 - Gone
500-599-----------------server side responses 500 - Internal Server Error. 503 - Service
Unavailable.
201 and 204
Q.diff between local storage and cookies?
local storage: for long data files
read data from browser side
As local storage was never intended to be secure, there is no data protection and any
JavaScript on the website
can access
Local storage provides at least 5MB
cookies:intended to read data from server side
For cookies, the maximum size is 4096 (4kb)bytes,

are read to small data volumes

Q.how to check db is working or not?


Q.Session auth and Token auth?
session auth: sessions are stored in memory at server side
we have an issue with this,a multiple users using system at once
Token auth: Tokens are stored at memory in client side
we don't have any issue because these are saved at client side

Q.JWT?
Q.size of the
Q.PostgreSQL trigger?
The triggers can be used to authenticate the input data.
It can easily retrieve the system functions.
CREATE Trigger
ALTER Trigger
DROP Trigger
ENABLE Trigger
DISABLE Triggercfdtr
it occurs when specific event occurs
Q.python memory management?
Python uses the dynamic memory allocation which is managed by the Heap data
structure.
It has stack and heap.in stack variables are stored and objects are stored in heap
memory.
if objects does not have any ref variable then it is eligible for GC
Q.what is a module in Python?
python file having some executable python code
it having functions and statements to
module makes the code easier understand and use.
Q.diff between charfield and text field?
CharField has a max_length of 255 characters while TextField can hold more than 255
characters.
Q.Http Request and Response?
Client give request.server gives response
Q.select related and Fetched related?
select related is always goto database and check for the request & give the response
fetch related is goto DB only once after that it will give the response for next time
Q.append and extend?
append takes the list as a element and add to end of the list
extend takes all the elements and add all the elements to end of the list
Q.Django Architecture?
Q.Relationships in Django?
Many-to Many:multiple authors and multiple users
one to one:one user to one author
one to many:one author many users
Q.diff between read() and readline()
read() reads all of the file's contents into a string, readline reads just a single line from
the file

with open("test.txt", "r") as file:..,dmnf


print(line)
o/p:first line

with open("test.txt", "r") as file:p


content = file.read()
print(content)
o/p:first line
second line
third line

37. Explain Q objects in Django ORM?


Q objects are used to write complex queries, as in filter() functions just `AND` the
conditions while if you want to
`OR` the conditions you can use Q objects. Let’s see an example:
Q.How to get a particular item in the Model?
ModelName.objects.get(id=”term”)
QHow to obtain the SQL query from the queryset?
print(queryset.query) or str(queryset.query)
Q.How can you combine multiple QuerySets in a View?
Initially, Concatenating QuerySets into lists is believed to be the easiest approach. Here’s
an example of how to do that:
from itertools import chain
result_list = list(chain(model1_list, model2_list, model3_list))
Q.diff between truncate and drop in SQL?
DROP Vs. TRUNCATE: Explore the Major Differences between DROP and TRUNCATE. In
SQL,
the DROP command is used to remove the whole database or table indexes, data, and
more. Whereas the TRUNCATE
command is used to remove all the rows from the table.
Q.What is mixin?
Mixin is a type of multiple inheritances wherein you can combine behaviors and
attributes of more than one parent class.
It provides us with an excellent way to reuse code from multiple classes. One drawback
of using these mixins is that it
becomes difficult to analyze what a class is doing and which methods to override in case
of its code being too scattered
between multiple classes.
Q.middleware in Django?
used for request and response purpose it also provides csrf token and authentication
Q.What is context in the Django?
Context is a dictionary mapping template variable name given to Python objects in
Django. This is the general name,
but you can give any other name of your choice if you wan
Q.What's the use of a session framework?
Using the session framework, you can easily store and retrieve arbitrary data based on
the pre-site-visitors.
It stores data on the server-side and takes care of the process of sending and receiving
cookies. These cookies just
consist of a session ID, not the actual data itself unless you explicitly use a cookie-based
backend.
Q.Cookies and sessions?
Cookies are client-side files on a local computer that hold user information. Sessions are
server-side files that contain
user data.
Q.Explain user authentication in Django?
Django comes with a built-in user authentication system, which handles objects like
users, groups, user-permissions,
and few cookie-based user sessions. Django User authentication not only authenticates
the user but also authorizes him.

Q.Explain the caching strategies in the Django?


storing the output results when they are processed
next time when the same results are fetched again, instead of processing again those
already stored results can be used,
which leads to faster accessing as well us less resource utilization. Django provides us
with a robust cache system that
is able to store dynamic web pages so that these pages don’t need to be evaluated
again for each request.
Q.What are Django Signals?
get notified when actions occur elsewhere in the framework
django.db.models.pre_init &
django.db.models.post_init
django.db.models.signals.pre_save & django.db.models.signals.post_save
django.db.models.signals.pre_delete &
django.db.models.signals.post_delete
3. What are models in Django?
A model in Django refers to a class that maps to a database table or database
collection.
Each attribute of the Django model class represents a database field.
Every model inherits from django.db.models.Model
The metaclass helps you set things like available permissions, singular and plural
versions of the name,
associated database table name, whether the model is abstract or not, etc.
5. What are views in Django?
A view function, or “view” for short, is simply a Python function that takes a web
request and returns a web response.
This response can be HTML contents of a web page, or a redirect, or a 404 error, or an
XML document, or an image, etc.
7. Define static files and explain their uses?
Websites generally need to serve additional files such as images. Javascript or CSS. In
Django, these files are referred to
as “static files”, Apart from that Django provides django.contrib.staticfiles to manage
these static files.
8. What is Django Rest Framework(DRF)?
Django Rest Framework is an open-source framework based upon Django which lets you
create RESTful APIs rapidly.
Q.features of Django?
Fast,Fully Loaded,Security,scalability,versatile
how to create a project in django?
django-admin startproject proj1
1.settings.py
2.wsgi.py
3.urls.py
4.__init__.py
5.manage.py
__init__.py ---it is a empty file.because of special name django treated this folder as
python package
settings.py ------we have to specify all our project settings and conf's.installed
applications,middleware config,DB config.
urls.py ------we have to store all our urls patterens of our project
every view or web page we have to define separate url pattern.end user can
use url pattern to access our webpage.
wsgi.py----web server gateway interface.
this is used for deploying our web application in production on online server.
manage.py-----this is mostly used python script in Django for run server,run
tests,migrations etc.
create app in django?
python manage.py startapp appname
admin.py ----used to register our models

Q.what is the role of web server or web interface?


this provides environment to run your web applications.and also web server is
responsible to receive the request and forward that request
to corresponding web component and give response to the end user

Q.delete and truncate difference?


delete a row ,slower,rollback,dml
truncate is to delete all rows,faster,don't rollback,ddl
QSQl commands in .subsets?
DDL,DML,DCL,TCL
Q.SQL DBMS?
software app interact with user for analyze and modifications like delete alter
Q.diff b/w field and table?
table having different manners like rows and columns.
field means column fields
Q.Joins inSQL?
combine rows and columns from two tables.
Q.char and varchar2?
varchar2----is used to strings of variable length in:varchar2(10)...it takes 6,8,2,etc
char-----is used to strings of fixed length ex:char(10) only 10 characters
Q.primary key?
uniquely identify columns
Q.what are constraints?
constraints are used to specify data type fields that can be specified while creating and
altering the tables.
NOT NULL:is used to specify the column is not allowed null value
CHECK:is used to satisfy the specific condition
Unique:this is used to specify the column with different values
Default:is used to specify default values when the column is not specified.
Index:is used to retrive and create data very quickly
Q.b/w SQL and MySql?
SQL:structured query language.like english.it is used to accessing and modifying the DB
MySql:Relational DBMS .it works on many platforms.it provides multi user access.
Q.unique key?
is identified a row with different values.allows null values and does not allow duplicate
values
Q.What is Foreign key?
is a ref for Primary key.
Fk is child table ref for parent table Primary key.
it provides link b/w two tables
Q.query for displaying current date?
select getdate();
Q.Inner join,Outere Join,self join,left join,full join,right join?
inner join():returns matching data from both the tables
Full join():join all the dats from both the tables.
left join():all the data from left table matching data from right table

right join():all the data from right


Q.what is index?
fast retrieval,performance tuning
three types of indexes.
1.clustered index:this index reorders the physical order of table.each table have only
one clustered index
2.non clusterd index:not reorder,each table have many non clustered indexes.
3.unique index:the colum does'nt allow the duplicate values
Q.diff b/w drop and truncate?
drop:removes table and can't rolled back
truncte:removes all the rows and can't be rolled back
Q.Normaliztion?
organizing the data to avoid duplicates and redundancy

Q.Trigger?
these are executed automatically in place or after data modifications.
before insert,after insert,before update,after update,before delete ,after delete
before:trigger activated before delete the recorn from table
after delete:trigger activated after delete the record from table
Q.group?
group function is used on the set of rows and gives one result per group
we use group functions at avg,count,max,min,sum
Q.relations in SQL?
one to one relationship:one record is related with another record in table b
one to many:one record is related with many record in table b
many to one:many records related with one record in table b
Q.merge?
conditional
Q.wht sql?
perform caluculations,manipulations
Q.highest salary of employee from employee table?
SELECT TOP 1 salary FRom
(SELECT top 3 salary from employee order by DESC)
order by ASC;
Q.CLAUSE?
limit the result,filter the rows
Q.Having and where?
Having is only applied with select statement.it is usually used in gruop by clause
where is aplied to each row before they are not part of group by clause
Q.How can you fetch records from two tables?
by using INTERSECT
ex:select studentid from studenttable InTERSECT select empid from emptable;

Q.manipulation functions?
upper,lower,
Q.agreegate function?
used to evaluate mathematical expressions and returns single value
Q.like operator?
is used for pattern matching
1. What is the use of Middlewares in Django?

Middlewares in Django is a lightweight plugin that processes during request and response
execution. It performs functions
like security, CSRF protection, session, authentication, etc.
Django supports various built-in middlewares.
1.SecurityMiddleware
2.SessionMiddleware
3.CommonMiddleware
4.CsrfViewMiddleware
5.AuthenticationMiddleware
6.MessageMiddleware
2. What is the difference between CharField and TextField in Django?
TextField is a large text field for large-sized text. In Django, TextField is used to store
paragraphs and all other text data.
The default form widget for this field is TextArea.
CharField is a string field used for small- to large-sized strings. It is like a string field in
C/C++. In Django,
CharField is used to store small strings like first name, last name, etc
3.Describe Django Field Class types?
Every field in a model is an instance of the appropriate field class. In Django, field class
types determine:

The column type describes the database about what kind of data to store (e.g.,
INTEGER, VARCHAR, TEXT).
The default HTML widget, while rendering a form field
4.What is the usage of "Django-admin.py" and "manage.py"?
Django-admin.py - It is a command-line utility for administrative tasks.
manage.py - It is automatically created in each Django project and controls the Django
project on the server or even to begin one.
It has the following usage:
Manages the project's package on the sys. path.
5.What are signals in Django?
Django provides a set of built-in signals that enable users to get notified of specific
actions.
pre_save
pre_delete
signals.request_started
6.What’s the difference between a project and an app in Django?
The app is a module that deals with the dedicated requirements in a project. On the
other hand, the project covers an entire app.
In Django terms, a project can contain different apps, while an app features in various
projects.
7.Explain Django URL in brief?
Django allows you to design URL functions however you want. For this, you need to
create a Python module informally called URLconf (URL configuration).

This module is purely a Python code and acts as a mapping between URL path
expressions and Python functions.
Django also provides a way to translate URLs according to the active language.
8.What are Django Exceptions?

ObjectDoesNotExist,FieldDoesNotExist,SuspiciousOperation,PermissionDenied,ViewDoesNotExi
st,MiddlewareNotUsed,ImproperlyConfigured,
FieldError,ValidationError.
9.Explain Django session
Django uses the session to keep track of the state between the site and a particular
browser. Django supports anonymous sessions.
The session framework stores and retrieves data on a per-site-visitor basis. It stores the
information on the server side and supports sending and
receiving cookies. Cookies store the data of session ID but not the actual data itself.
10.What are Django cookies?
A cookie is a piece of information stored in the client's browser. To set and fetch
cookies, Django provides built-in methods.
We use the set_cookie() method for setting a cookie and the get() method for getting
the cookie.
You can also use the request.COOKIES['key'] array to get cookie values.
11.Flask vs. Django: What's the difference between Flask & Django?
Flask and Django are the two most popular Python web frameworks.
Django:
High-level Python web framework for easy and simple projects.
Full-stack web framework
Templates, Admin, and ORM are Built-in
Django does not support visual debugging.
Django Web Framework supports a large number of third-party applications.
Flask:
Low-level Python web framework.
WSGI (Web Server Gateway Interface ) framework
Templates, Admin, and ORM are Built-in Requires installation
Flask Web Framework doesn't offer support for third-party applications.
Flask supports visual debugging.
12. How to check the version of Django installed on your system?
To check the version of Django installed on your system, open the command prompt
and enter the following command:

py -m django --version
13.Give a brief about Django Admin.
Django Admin is the command-line utility for administrative tasks. It's a preloaded
interface to fulfill all web developer's needs and is imported from the
"django.contrib packages".
Django Admin interface has its user authentication and offers advanced features like
authorizing the access, CMS (Content Management System),
managing various models, etc.
14.How do you create a Django project?
To create a Django project, navigate to the directory where you want to do a project
and type the following command:
django-admin startproject ABC
That will create an "ABC" folder with the following structure −
ABC/
manage.py
myproject/
__init__.py
settings.py
urls.py
wsgi.py
15.Name some companies using Django.
Various companies out there are using Django. Of them, major are Instagram, Pinterest,
Udemy, Mozilla Firefox, Reddit, etc.
16.How do Django views work?
Django views are the critical component of the framework They serve the purpose of
encapsulation. They encapsulate the logic liable
to process a user's request and return a response to the user.
Either they return HTTP responses or raise an exception such as 404 in Django. Besides,
Views also perform tasks like reading records from a database,
generating PDF files, etc.
Every app in Django comes with a views.py file, and this contains the views functions.
Views function can be imported directly in the URLs file in Django.
To achieve that, you have to import the view function in the urls.py file first and add the
path/URL that the browser should request to call that View function.
17.Give a brief about Django Template?
Django Templates generate dynamic web pages. Using templates, you can show the
static data and the data from various databases connected to the app
through a context dictionary. You can create any number of templates based on project
requirements. Even it's OK to have none of them.
Django template engine handles the templating in the Django web framework. Some
template syntaxes declare variables, filters, control logic, and comments.
Django ships built-in backends for its template system called the Django template
language (DTL).
18.Describe Django ORM.
interact with databases in a more pythonic way like we can avoid writing raw queries, it
is possible to retrieve, save,
delete and perform other operations over the database without ever writing any SQL
query. It works as an abstraction
layer between the models and the database.
19.When to use iterators in Django ORM?
Iterators are containers in Python containing several elements. Every object in the
iterator implements two methods that are __init__() and the __next__()
methods.
In Django, the fair use of an iterator is when you process results that take up a large
amount of memory space. For this, you can use the iterator() method,
which evaluates the QuerySet and returns the corresponding iterator over the results.

USER authentication methods?


django take care of all these.django have inbuilt applications.Django uses BCRYPT and
argon2.argon2 is more secure than bcrypt.
for that we have to configure password hashers in settings.py file

1 .what is decorator:-
A.decorator in py are essential functions that add functionality to an existing function
in py without changing the structure of
the function itself.
program of decorator:-
def shout(text):
return text.upper()
def load(text):
return text.lower()
def greet(fun)
#storing the function in a variable
a=fun("thr kfhif")
print(a)
greet(shout)
greet(load)
2.what is GENERATOR:
A Generator function is defined like a NORMAL FUNCTION .but whenever it needs to
generate a value,So with the YIELD KEYWORD rather than return..
program of generator:-
def simpleGeneratorFun():
yield 1
yield 2
yield 3

# Driver code to check above generator function


for value in simpleGeneratorFun()
print(value)

OUTPUT;-

1
2
3

3.what is CONSTRUCTOR?
CONSTRUCTOR are special type of method used to Initialize an object. And constructor are
responsible for assigning values to the data member of a class
when the object is created.
def __init__(self):
# body of the constructor

4.WHAT IS MULTITHREADING IN PYTHON?


Multithreading allows the programmer to divide application tasks into sub-tasks
and simultaneously run them in a program.
It allows threads to communicate and share resources such as files, data, and
memory to the same processor.

5.WHY IS TUPLE FASTER THAN LIST?


Tuple is stored in a single block of memory. Creating a tuple is faster than creating a list.
Creating a list is slower because two memory blocks need to be accessed. An element in
a tuple cannot be removed or replaced.

6.WHAT IS PYC FILE IN PY?


pyc file is created by the Python interpreter. when a *. py file is imported into any other
python file.
The *. pyc file contains the “compiled bytecode” of the imported module/program so
that the “translation” from
source code to bytecode can be skipped on subsequent imports of the *. py file.

7.WHAT IS EXCEPTION?
AN Unwanted and unexpected event which disturbs normal flow of program is called
exception .

8.WHAT IS MIGRATIONS IN DJANGO?


Migrations are Django's way of propagating changes you make to your models (adding a
field, deleting a model, etc.) into your database schema.

9.WHAT IS YIELD?
The Yield keyword in Python is similar to a return statement used for returning values.
However, there is a slight difference.
The yield statement returns a generator object to the one who calls the function which
contains yield, instead of simply returning a value.

10. WHAT IS RETURN STATEMENT?


The Python return statement is a special statement that you can use inside a function.
A return statement can return a value to the calling function.

11.What is the difference between multithreading and multitasking?


Multitasking lets the CPU perform various tasks simultaneously (threads, process,
program, task),
while multithreading helps in the execution of various threads in a single process
simultaneously.

12.WHAT IS INSTANCE METHOD?


Instance method implementation if we are using instance variable than such type
method are called instance method.
EX:-def m1(self) we have to pass self variables
13.WHAT IS INSTANCE VARIABLE?
INSTANCE Variable if the value of the variable is varied from object to object.
kxv
14.WHAT IS STATIC VARIABLE?
If the value of the variable is not varied from object to object.

15.WHAT IS CLASS?
TO create objects we require some models are plans or blueprint.we can write a class to
represent properties and action.
properties can be represented by variables.action can be represented by method.
16.WHAT IS OBJECT?
Object is an instance of a class.
17.WHAT IS INHERITANCE? INHERITS properties from base class to derived class
1.single inheritance
2.multiple inheritance
3.multilevel inheritance
4.hierarchical inheritance

18.WHAT IS ABSTRACTION?
Abstraction is nothing but that shows only essential attributes and hides unnecessary
information to the users.

19.WHAT IS ENCAPSULATION?
Binding data together method and data in a single unit is called encapsulation.

20.WHAT IS POLYMORPHISM?
Polymorphism is a method in oops,that performs different things as per object class.

21) What is PEP 8?


PEP 8 is a coding convention, a set of recommendations, about how to write your Python code
more readable.

22)How memory is managed in Python?


• Python memory is managed by Python private heap space. All Python objects and data
structures are located in a private heap. The programmer does not have access to this private
heap and the interpreter takes care of this Python private heap.
• The allocation of Python heap space for Python objects is done by the Python memory
manager. The core API gives access to some tools for the programmer to code.
• Python also has an inbuilt garbage collector, which recycles all the unused memory and frees
the memory and makes it available to the heap space.

23) What are Dict and List comprehensions?


They are syntax constructions to ease the creation of a Dictionary or List based on existing
iterable.

24)Mention what are the rules for local and global variables in Python?
Local variables: If a variable is assigned a new value anywhere within the function's body, it's
assumed to be local.
Global variables: Those variables that are only referenced inside a function are implicitly global.

25)What is docstring in Python?


A Python documentation string is known as docstring, it is a way of documenting Python
functions, modules and classes.

26) What is a namespace in Python?


In Python, every name introduced has a place where it lives and can be hooked for. This is
known as namespace. It is like a box where a variable name is mapped to the object placed.
Whenever the variable is searched out, this box will be searched, to get corresponding object

27)what is the difference between List and array?

28)what is the difference between range() and xrange()?

29)what are the advantages of python?

30) what is recursive function?

31) what is recursive function?

32)what are the namespaces?

33)what are access modifiers ?

34)why we need _init_ method?

34)what is call by value and call by reference method?

34)what is module?

35)what is diff b/w module and package?

36)what is concept of monkey patching?

37)what is memory management in python?

38)what is PEP-8in python?

39)what is decorator?

40) what is difference b/w .py and.pyc file?

41)what is abstraction ?
42)what is encapsulation?
43) what is pickling and unpickling?
44)explain how delete file in python?
45)what are built in datatypes that are present in python?
46)Explainhow can you make a python script executable on unix?
47)what is the difference between flask and Django?
48)what is the common way for flask script to work?
49)what are iterators in python?
50)what is garbage collector in python?
51)what is multithreading and multiprocessing?

—--> Interview programs for pandas

1. Write a Pandas program to create and display a one-dimensional array-like object


containing an array of data using Pandas module
A) import pandas as pd
ds = pd.Series([2, 4, 6, 8, 10])
print(ds)
2)Write a Pandas program to convert a Panda module Series to Python list and it’s type.?
A)import pandas as pd
ds = pd.Series([2, 4, 6, 8, 10])
print("Pandas Series and type")
print(ds)
print(type(ds))
print("Convert Pandas Series to Python list")
print(ds.tolist())
print(type(ds.tolist()))
3). Write a Pandas program to add, subtract, multiple and divide two Pandas Series. Go to the
editor
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
A)import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 9])
ds = ds1 + ds2
print("Add two Series:")
print(ds)
print("Subtract two Series:")
ds = ds1 - ds2
print(ds)
print("Multiply two Series:")
ds = ds1 * ds2
print(ds)
print("Divide Series1 by Series2:")
ds = ds1 / ds2
print(ds)
Write a Pandas program to compare the elements of the two Pandas Series.
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 10]
A)import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 10])
print("Series1:")
print(ds1)
print("Series2:")
print(ds2)
print("Compare the elements of the said Series:")
print("Equals:")
print(ds1 == ds2)
print("Greater than:")
print(ds1 > ds2)
print("Less than:")
print(ds1 < ds2)
IMPORTANT PRACTICE PROGRAMS ON PANDAS DATA FRAMES

Write a Pandas program to get the first 3 rows of a given DataFrame.

Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

Sample Solution :

Python Code :

import pandas as pd
import numpy as np

exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',


'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

df = pd.DataFrame(exam_data , index=labels)
print("First three rows of the data frame:")
print(df.iloc[:3])
Sample Output:

First three rows of the data frame:


attempts name qualify score
a 1 Anastasia yes 12.5
b 3 Dima no 9.0
c 2 Katherine yes 16.5
Write a Pandas program to count number of columns of a DataFrame.
SOLUTION:
import pandas as pd
d = {'col1': [1, 2, 3, 4, 7], 'col2': [4, 5, 6, 9, 5], 'col3': [7, 8, 12, 1, 11]}
df = pd.DataFrame(data=d)
print("Original DataFrame")
print(df)
print("\nNumber of columns:")
print(len(df.columns))
Sample Output:

1. Which data type is classified as mappings, sequence, set, text?

2. Difference between set and tuple?

3. I have a json file called userdata.json and I have an object for user1 and user2. For that user1
and user2 has a key : value pair of firstname and lastname . write a script to modify the data of
userdata.json file and add two more key : value pairs to each json object called location and
mail id and return me the json file. What are the steps?

4. What is pickling?

5. What is lambda?

6. What is list comprehension? And give me a real time example?


7. Fibonacci series of all even numbers in the range of 10 to 50 using list comprehension?

8. Logic for even prime numbers in the range of 100 to 1000?

9. Input = “Sai Zenith is an engineer from Hyderabad”

Output = S__ Z_n_th __o_ HYDERABAD

10. Architecture of Django?

11. What are urls?

12. Write a model to get the username and password, in the backend also it will integrate the
database?

13. What is a git stash?

14. What is a git cherry pick?

15. What is the difference between git clone and git remote?

16. Stages of SDLC?

17. What are the Agile ceremonies that you have been involved in?

18. Cloud architecture?

19. Analytical Question - Time - 3 : 50. What is the angle between the hour and minute hand?

1.what is pythonpath ?

2.what is Pass ,continue and Break ?

3.what is Lambda function ?

4.what is difference between List and array ?

5.what is difference between List and sets?

6.what is Decorator ?

7.What is PEP-8 ?

8.what are joins in SQL?


9.what is authentication?

10.what is signals in Django?

11. What is inheritance and how many types of inheritances ?

12.what is ORM in django ?

13.what is pickling and unpickling in python?

14.what is exception and how to handle exceptions?

15.What are the daily activities in office?

16.Why we use git push and git pull?

17.what isgit-commit ? what it does?

18.can you mention commands while creating a Django project?

19.what is list comprehension and give one example?

20.write a program for FOURTH largest number in the list?

21.what is middleware in django?

22.what is git init?

1.what is decorator in python.


2.write a python program for decorator.
3.write a python program for arbitrary arguments.
4.what is django MVT pattern.
5.what is middleware in django.
6.what is difference between list and tuple.
7.how many types of joins in sql .
8.what is inner join.
9.what is user authentication.
10.what is view in sql.
11.what is lambda function.
12.what is generator.
13.what database used in django.
14.what are http methods in django.
15.what is difference between put and patch method in django.
16.what is primary key in sql.
17.what is foreign key in sql.
18.what is difference between unique and primary key in sql.
19.what is ORM In django.

1. Create a dictionary with keys and values and change the key as value and value is key
2. Create a list with some numbers write a function to find the second minimum
3. Create a class with constructor with an id and initialize the id and create two objects
with different numbers, then you need to add the objects and get the sum of two id’s
4. Can you explain the left join in sql
5. Can you explain the outer join
6. Can you explain multithreading
7. When do you use multithreading and when do you use multiprocessing
8. Any example for multiprocessing
9. Real world example for multithreading and multiprocessing
10. Can you explain generate function
11. Why should I use generate instead of normal function
12. Can you explain method overriding and overloading
13. Can you explain why should I use exception handling
14. Do you know about dockers
15. What is your current role in your project

1. What is multi threading were we use in your project?


2. What is multi processing system?
3. Do you have any experience of mongodb?
4. What is outer join ?
5. What is method over riding?
6. Design three classes for 1 is employee 2 is manger and 3 is department represent this
three classes?
7. What is messaging systems?
8. Create two employee objects?
9. What is self in python?
10. What is static method
1)At CRED you have to be on call for a day. But rotation policy is bit weird. Assume you have T
members on your team and your number is K out of T.so first we go from member 1 to T
rotating each day, then we go from member 1 to T and so on.
So given the number of days D since the process started and assuming team members
remained the same for this duration, calculate for which you will be on call.

Examples:
1)T=6, K=3, D=15
1.[3,10,15]
2)T=1, K=1, D10
1.[1,2,3,4,5,6,7,8,9,10]
3)T=2, K=1, D=10
1[1,4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33,36,37]
4)T=11, K=5, D=100
[5,18,27,40,49,62,71,84,93]

Sol)
def onmyCallDays(T,K,D):
lst=[]
for I in range(D//T):
if i%2==0:
lst.append(K+T*i)
else:
lst.append(lst[-1]+(T-K)*2+1)
return lst
print(onmyCallDays(11,5,100))

output:
[5,18,27,40,49,62,71,84,93]
2) How to call API URL using python and print only headers.

3) How to check particular product listed in all websites using python?

1. what is authentication in django?


2. What is JWT tokens?
3. Can you list status code?
4. When you get most 400 request? And what type of bad request?
5. What is middleware in django?
6. What is collections in python?
7. Write a program for below input (input:aabbcssttddffaaaaagggggeeee) and
(output :a2b2c1s2t2d2f2a5g5e4)

1. Apart from python what are the text ta


2. Take a string write a function
S = “ python is very good”
Output = nohtyp si yrev doog
3. Write a decorator to this function to capitalize the last letter of the word
Output = nohtyP sI yreV dooG
4. You have a employee table with emp name, emp id, salary, month and year write a ORM
query to get avg salary drawn by each employee in last year
5. Can you write a sql query for the same
6. What is CSRF token, why it is used
7. What is Django signals why it is used
8. What is the code version do have used
9. Why are you using this git repository
10. For example you working in a team and some one has made changes now you want to
revert back, what do you do

1. Can you write a Fibonacci program in a recursive function


2. Take a list with random numbers and print the repeated numbers in a list if 4 can
appears 3 times then you need to print tow 4’s
3. How did you deploy your code
4. Where are these api’s hosted that you have worked in
5. Have you worked on any CI CD pipe lines
6. Did you follow any branching and merging strategies
7. Multiple people working on a same code based how did you manage that no conflicts
are appear
8. In python which libraries you have used heavily
9. Have you used multithreading
10. Which module you used for multithreading
11. Have you used multiprocessing
12. Have you worked on any other frame works
1.What is polymorphism/explain about polymorphism
2.How do you delete table in SQL
3.What is the syntax for Deleting error
4.How could you multiple tables at a same time
5.How to update multiple tables in a same time
6.What is frozen set
7.What are immutable data types in python
8.What is the difference between tuple and frozen set
9.Take a string and print the string without white spaces
10.Could you print string in the reverse order
11.Print only first three letters by reverse string as which you taken the string
12.Could you write example for palindrome
13.How do you unpack tuple
14.Take a tuple and unpack the tuple
15.What is garbage collection in python
16.When we exit a python all memory will be deallocated or not
17.What is module
18.Is this possible to import a module in dynamical way or not (OR)Is this possible load a
module in run time
19.You have a tuple could you print it one by one
20.What is view in Django
21.What is model
22.What is array field in Django
23.How do create a drop down without using styles
24.What is Foreign key
25.Is this possible to use a single Foreign key multiple times in a model
1. Why should we use models and views in django explain briefly?
2. What is pandas and what are the uses?
3. combine two data frames how you will do that?
4. How i will find all employes who have joined in 2022? write a query of this question?
5. write a code using pandas find all all employes who have joined in 2022?
6. you have empoly table : emply id,date of joining,first name,last name,salary ,dep id and dep
table: dep id , dep name so you want find out in which dep which is having highest cumulative
salary?

1. Time management skills(How do you manage time on few tasks).


2. Scenario used set instead of list(example).
3. Difference between set and list.
4. Which one is faster list or set to find the elements.
5. Do you know about assert keyword.
6. Difference between break and continue and pass statements.
7. Explain about ORM in django.
8. Explain about session management.
9. Difference between one-to-one field and foreign key field.
10. Explain the filter query in django with example.
11. Table(employees) and fields(id,name,age,place) and ( i need the name and id of 4
employees within the age of 25 and 30 from chennai. (SQL query and django query
example).
12. Explain between get and filter in django ORM.

1. What is difference between list and tuple?


2. What is difference between extend method and append method?
3. Have you use set in python? What is the primary thing in sets?
4. You have a million of data they requirement is we need to take specifically take one
data what did you do ? what type of data structure you use?
5. Tuple is faster than set?
6. How is in operator implement in sets?
7. What is a hash function done?
8. What is a faster hash compression or value compression?
9. can u tell me about dictionary in python
10. why does keys was not allow duplicates?
11. How do u fine any element in dictionary?
12. How to iterate over a dictionary?
13. Which data type that allow keys to dictionary?
14. Does python allow multithreading?
15. Why does multithreading is not give good performances in python?
16. What is existing role in multithreading?
17. What is GIL and what is its functions?
18. What is multiprocessing?
19. What is main difference between multithreading and multiprocessing?
20. garbage collection is allow in python?
21. Write a program for list of prime numbers?

1.What is Django
2.where do you define data base collection in Django
3.can I have multiple DB connection
4.what is difference between get and filter method in Django
5.input=[hello world] o/p [h:1,e:1,l:3,o:2,w:1,r:1,d:1] write a code for that
6.what is polymorphism
7.what is the types of polymorphism explain
8.do you have polymorphism in python
9.what are the types of inheritance explain
10.suppose if I have class A class B class c which will be execute
11.what is MRO
12.what is abstract class
13.how do you whether class is abstract or not explain with examples
14.explain try, except, else, finally
15.what will happen to the code if you don’t use try& exception
16.in Django we have mixins signals, explain
17.why we will use debug=”true” in the project production level
1. Give me a brief introduction about your first project optum clinical manager
2. What is the role in this project
3. Were you involve designing this project
4. What exactly you do while developing the webpages
5. How do you create a Django app
6. How do you deploy a Django webapp
7. How do you print hello world by searching the /hello
8. "Design/Develop for a document management system that requires the following
feature set.

1. Documents of different types (PDF/DOC/DOCX/XLS/XLSX..) should be submittable.


2. Each document falls into a particular category and goes through an multi-level
approval workflow which should be configurable based on the category.
3. Documents should be searchable based on metadata (originators/approvers/category
etc.) and also the document content.
4. There should be provisions to revise, delete, or void documents within the workflow.
5. Older versions of the document should be retained.
6. Email notification subscription per document/per category should be provided.
Notifications should be sent out whenever a document is released or revised."

1. Can you brief me about you project?


2. What are rest_api’s ?
3. What kind of ORM libraries you are worked in ?
4. Did you try to connect multiple tables as well using ORM?
5. Which function you used to join tables?
6. By using ORM to connect to DB, did you ever face error ?called too many clients.
7. How can you handle many connections at a time to your sqlAlchemy connecting to db,
that you can have thousand requests at same second, do you think your application can
survive?
(or)
Normally in postgresql db configuration they specified who ever installed the db
maximum of 100 requests, if you receive more than 100 requests you will get an error
or an exception then how you can handle them.
8. How do you deploy your python application in a server?
9. Why we can use Gunicorn server because python its self provides a wsgi server right?
10. Did you face the error in wsgi server by deploying huge data?
11. What is the use of Gunicorn?
12. If we don’t use Gunicorn what happens?
13. How we can implement multithreading in python? Is there any library or module?
14. In the part of python documentation, due to global interpreter lock it doesn’t support
multithreading , how do you see it?
15. What is the difference between multithreading and multiprocessing?
16. Did you ever write unit tests in your python application?
17. What is the most challenging task you are facing?

1. Introduce yourself
2. What is the difference between list and tuple
3. Can you explain the set data structure
4. What is the difference between constructor and a method
5. How many types of functions in python
6. Can you please differentiate interface and abstraction class
7. D = {“A”:[1,2,3,4],”B”:[2,4],”c”:4} the output should be only integer not a
list ..output:- c 4
8. a = [10,20,30,40,50] you need to square all the elements in the list, using the list
comprehension
9. What do you mean by dataframe in pandas
10. Why we need to go for pandas
11. What is the main difference between drop and delete
12. How can you rename the table name
13. How can you delete a row which is having employee salary 50,000
14. What is the use of primary key constraint
15. I would like to add another column to an existing table how can you do that
16. What is the use of git basically
17. Suppose you working on a child branch, I am also working on the same branch, so
can get conflict or not

1. Do you know any other programming languages


2. Why do you choose specifically python
3. What is the advantage of python language for clients
4. Do you know the differences between Flask and Django
5. Can I able to heavy weight application with flask with thousands of end points
6. Do you know any library that flask doesn’t support and Django does supports
7. What is your carrier aspirations, where you want to be in next two years or four years
8. Do learn any library for Data science
9. What do mean by concurrent request
10. How many users can be hit the api’s at the same time
11. What is the load that Django will take
12. How many users can take the response concurrently
13. You have a table that contains 1 million records, so you need to search a record, for that
how much of time it will take to that query
14. How can you make the query execute in 1 sec
15. What is index
16. Is it possible to putting indexes to all columns
17. Do you know about data base shording

1.Given an array of integers nums.


A pair (i,j) is called good if nums[i] == nums[j] and i < j.
Return the number of good pairs.
Example 1:
Input: nums = [1,2,3,1,1,3]
Output: 4
Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.

2. We have a employee table we need to update address and phone no in a record, so you can
write the logic by using the Rest_API’s in Django
3. Can you tell me the difference between list and tuple
4. Where we use the list and tuple
5. What is the difference between filter and map functions
6. What is a decorator
7. Can you write the decorator function with time caluculation

INTERVIEW QUESTIONS BY MAPLELABS on 27-JUL-2022.

1. How do you find python after working 3 years (Any challenges)?


2. What do you mean by memory space?
3. What is meant by interpreter language?
4. What and why are ( .pyc) files used?
5. What are data types in python ?
6. List and tuple differences?
7. List comprehension definition and uses?
Can we use it for reversing a list?
8. do you know what are virtual environments?
9. Can you tell more Advantages of virtual environments?
10. What are decorators explain with examples?
11. What is lambda write an example?
12. What are map ,filter and reduce functions write an example to use them?
13. *What are generators and how they are different from iterators?
14. Can you give me use case for generator where iterator not used?
15. What should be nature of file when we use iterator?
16. 1 lakh records needed to be processed what will be used generator or iterator?
17. What do you understand by serialization?
18. What is a module in python? What is a package, what is difference b/w module and
package?
19. Do you know what are dunder methods and magic methods? Why they are special?
20. Explain Abstraction with real time example?
21. What is encapsulation give example?
22. What is Inheritance and types ,difference b/w multiple and multilevel inheritance?
23. What is polymorphism and explain with example?
24. Explain Django Architecture ?
25. What are middleware?
26. Explain what is template ?
27. What is meant by django rest frame work?
28. What is ORM? How do you use it to get the required data?
29. What is Django field class ? can we use it for the purpose of getting id’s?
30. *What are inheritance types in Django?
31. Explain about Mixings in Django ?
32. How do we define static in Django (static files)?
33. How do you create superuser?
34. How is your experience with linux ? have done any done scheduling in OS?(periodical
running python file)
35. Have you installed any services in operating systems?
36. Where did you host the Django in OS ? who will set it up?
37. Do you know about symbolic links or simlinks?
38. Can you list all the files in a directory? Write command for that in linux ?
39. Can you find hidden files? Write command for that in linux?
40. What are multiprocessing and multi threading? How are they different?
41. What is difference b/w a thread and a process? How they are different?
42. Which of them possible in python? What is problem with multithreading in python?

NHCL

1)How work is defined in your company?

2)What libraries you used in your project?


3)How to create Bar charts and pie charts?

4)What is slicing in python?

5)How to check the word is palindrome or not?

6)What is the difference between list and tuple?

7)How to remove particular element in list?

8)Difference between remove and pop in list?

9)What is Docstring?

10)Why we use Functions?

11)What is Matrix?

12)For random numbers which module we need to import?

13)what modules you used in your project?

14)How to import Excel file to your project without Null values?

You might also like