0% found this document useful (0 votes)
86 views26 pages

Premier Programme

Python can be used for both web client and server side programming, but is best suited for server side applications. It allows structured and object oriented programming and has extensive module support. Common data types in Python include lists, tuples, sets, and dictionaries.

Uploaded by

christ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views26 pages

Premier Programme

Python can be used for both web client and server side programming, but is best suited for server side applications. It allows structured and object oriented programming and has extensive module support. Common data types in Python include lists, tuples, sets, and dictionaries.

Uploaded by

christ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Q # 1) Can Python be used for web

client and web server side programming?


And which one is best suited for
Python?

Answer: Python is best suited for web


server side application development
because of its large feature set for
logical business creation, database
interactions, web server hosting, etc.

However, Python can be used as a web


client side application that needs a
few conversions for a browser to
interpret client side logic. Also note
that Python can be used to create
desktop applications that can run as a
stand-alone application, such as
utilities for test automation.

Q # 2) List at least 3-4 advantages of


using Python over other scripting
languages such as JavaScript.
Answer: Below are some of the benefits
of using Python.

Application development is faster and


easier.
Extensive module support for any type
of application development including
data analysis / machine learning /
math-intensive applications.
A great supportive community to get
your answers.

Q # 3) Explain List, Tuple, Set, and


Dictionary and provide at least one
instance where each of these collection
types can be used.

Reply :

List: A collection of items of


different data types that can be
modified at run time.
Tuple: Collection of elements of
different data types that cannot be
changed. It has only read-only access
to the collection. This can be used
when you want to find your data
collection set that does not require
any modification.
Set: A collection of elements of a
similar data type.
Dictionary: Collection of items with
key-value pairs.
Generally, list and dictionary are
widely used by programmers, as both
provide flexibility in data collection.

Q # 4) Does Python allow you to program


in a structured style?

Answer: Yes. It allows coding in a


structured and object oriented style.
It provides excellent flexibility to
design and implement your application
code according to your application
requirements.

Q # 5) What is PIP software in the


Python world?
Answer: PIP is an acronym for Python
Installer Package which provides a
transparent interface to install
various Python modules. It is a command
line tool that can search the internet
for packages and install them without
any user interaction.

Q # 6) What should be the typical build


environment for developing Python-based
applications?

Answer: You just need to install the


Python software and using PIP you can
install various Python modules from the
open-source community.

For IDE, Pycharm is highly recommended


for any kind of application development
with extensive support for plugins.
Another core IDE is called RIDE and is
part of the open source Python
community.
Q # 7) What tools can be used to test
the unity of your Python code?

Answer: The best and easiest way is to


use the standard python "unittest"
library to test units / classes. The
supported features are very similar to
other unit testing tools like JUnit,
TestNG.

Q # 8) How do the For Loop and While


Loop differ in Python and when do you
choose to use them?

Answer: For Loop is typically used to


iterate through items in various
collection types such as List, Tuple,
Set, and Dictionary.

The While Loop is the actual looping


function used in any other programming
language. This is how Python differs in
handling loops from other programming
languages.
Q # 9) How are datatypes defined in
Python and how many bytes do integer
and decimal datatypes contain?

Answer: In Python, it is not necessary


to explicitly set the data type of a
variable.

Based on the value assigned to a


variable, Python stores the appropriate
data type. In the case of numbers such
as Integer, Float, etc., the length of
the data is unlimited.

Q # 10) How do you use arrays in


Python?

Reply: Python does not support arrays.


However, you can use the List
collection type which can store an
unlimited number of items.

Q # 11) How do you implement JSON given


that Python is best suited for the
server side application?
Answer: Python has built-in support for
handling JSON objects.

You just need to import the JSON module


and use the functions like loads and
dumps to convert from JSON string to
JSON object and vice versa. This is a
simple way to manage and exchange JSON
based data on the server side.

Q # 12) What's the best way to parse


strings and find patterns in Python?

Answer: Python has built-in support for


parsing strings using the Regular
Expression module. Import the module
and use the functions to find a
substring, replace part of a string,
etc.

Q # 13) What databases are supported by


Python?
Answer: MySQL (structured) and MongoDB
(unstructured) are the main databases
natively supported in Python. Import
the module and start using functions to
interact with the database.

Q # 14) What is the purpose of the


_init_ () function in Python?

Answer: This is the first function that


is executed when an object of a class
is instantiated. This is equivalent to
the concept of constructor in C ++.

Q # 15) What is the meaning of the


"self" parameter in an object method?
Should we always call this parameter
“self”?

Answer: The "self" parameter is used to


refer to the object properties of a
class. The "self" parameter is supposed
to be prefixed with the properties of
the class object.
The answer to the second part of the
question is no. The "self" parameter
can have any name.

Q # 16) How is Lambda function


different from a normal function in
Python?

Answer: Lambda is similar to inline


function in C programming. It returns a
function object. It contains only one
expression and can accept any number of
arguments.

In the case of a normal function, you


can define a function name, pass the
parameter and necessarily have a return
statement. The Lambda function can
generally be used for simple operations
without the use of function names. It
can also be used in place of a
variable.

Q # 17) How is exception handling done


in Python?
Answer: There are 3 main keywords
namely try, except and finally which
are used to catch exceptions and manage
the recovery mechanism accordingly. Try
is the block of code that is watched
for errors. Except that the block is
executed when an error occurs.

The beauty of the final block is to


execute the code after trying an error.
This block is executed regardless of
whether an error has occurred or not.
Finally, the block is used to perform
the required cleaning activities of the
objects / variables.

Suggested reading = >> How to handle


exceptions in Python

Q # 18) What is the starting point for


executing Python code?
Answer: Since 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 must have the
following special variable defined in
your source file as:

if__name __ == "__main__
main ()

Q # 19) Name some of the important


modules available in Python.

Answer: The networking, math,


cryptography, internet data processing,
and multi-threading modules are
important modules. Apart from these,
there are several other modules
available in the Python developer
community.
Q # 20) Which Python module (s) can you
use to measure the performance of your
application code?

Answer: The time module can be used to


calculate the time at different stages
of your application and use the logging
module to save data to a file system in
any preferred format.

Q # 21) How do you start subprocesses


in the main process of a Python
application?

Answer: Python has a built-in module


called a sub-process. You can import
this module and use the run () or Popen
() function calls to start a subprocess
and get control of its return code.

Q # 22) Since Python is more suitable


for the server side application, it is
very important that threading is
implemented in your server code. How
can you achieve this in Python?
Answer: We should use the threading
module to implement, control and
destroy threads for parallel execution
of server code. Locks and semaphores
are available as synchronization
objects to manage data between
different threads.

Q # 23) Do we need to call the explicit


methods to destroy allocated memory in
Python?

Answer: Garbage collection is a built-


in feature of Python that supports
memory allocation and deallocation.
This is very similar to the
functionality of Java.

Therefore, there is much less chance of


memory leaks in your application code.

Q # 24) Does the same Python code work


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

Q # 25) How can you build a GUI based


application in Python for client side
functionality?

Answer: Python with the Tkinter


standard library can be used to build
GUI based applications. The Tkinter
library supports various widgets which
can create and handle widget specific
events.

Q # 26) What are the different


environment variables identified by
Python?

Reply:
PYTHONPATH: This environment variable
helps the interpreter to locate the
module files imported into the program.
PYTHONSTARTUP: This environment
variable contains the path of the
initialization file containing the
source code.
PYTHONCASEOK: This variable is used to
find the first case-insensitive match
in the import statement

Q # 27) What are Python tuples and how


are they different from lists?

Answer: Tuples are basically a sequence


of elements separated by commas and
placed in parentheses.

Lists, while it is a sequence of items


separated by commas and in square
brackets. In addition, tuples cannot be
updated while, in lists, elements can
be updated with their sizes.
Q # 28) What does the "#" symbol do in
Python?

Reply: "#" Is used to comment on


anything that comes after on the line.

Example:

print (“I am a beginner in Python”)


#print (“I am a beginner in Python”)
Production:

I am a beginner in Python

Q # 29) What is stringVar doing. strip


() done?

Reply: This is one of the string


methods which removes leading /
trailing white space.
Q # 30) What should be the output of
the following code:

a = "pythontutorial" print (‘%. 6s’%


a)
Reply: Production: python

Insert Sorting Doubly Chained List Java

Q # 31) Write a command to read:

a. '10' characters from a file


b. Read entire file
vs. Write the output after running the
two commands together.

Where the file name is


"softwaretestinghelp.txt".

File text:

Python is a powerful, high-level


object-oriented programming language
created by Guido van Rossum.

It has simple and easy to use syntax,


making it the perfect language for
someone who is trying to learn computer
programming for the first time.
Reply:

f = open ('softwaretestinghelp.txt',
'r') print (f. read (10)) print (f.
read ())
Production:

Python

is a powerful high level object


oriented programming language created
by Guido van Rossum.

It has simple and easy to use syntax,


making it the perfect language for
someone who is trying to learn computer
programming for the first time.

Q # 32) What are membership operators


in Python? Write an example to explain
both.

Answer: There are 2 types of membership


operators in Python:
in: If the value is found in a
sequence, then the result becomes true
if not false

not in: If the value is not found in a


sequence, then the result becomes true
if not false

Example:

a = 15 b = 30 list = [3,6,15,20,30]; if
(a in list) print “a is available in
given list” else print “a is not
available in given list” if (b not in
list) print “b is not available in
given list” else print “b is
available in given list ”
Production:

a is available in a given list

b is available in the list

Q # 33) Enter a code to display the


current time.
Reply:

currenttime = time.localtime (time.time


()) print (“Current time is”,
currenttime)

Q # 34) What is the output of print str


[4:] if str = 'Python Language'?

Reply:

Production: on the tongue

Q # 35) Write the command to get all


the keys from the dictionary.

Reply: print dict.keys ()

Q # 36) Write a command to convert a


string to an int in python.

Reply: int (x [, base])


Q # 37) What are helper () and dir ()
in python?

Reply: help () is a built-in function


that can be used to return the Python
documentation of an object, method,
attributes, etc.

dir () displays a list of attributes


for the objects that are passed as
arguments. If dir () has no arguments,
it returns a list of names in the
current locale.

What Is The Difference Between Quality


Assurance And Quality Control

Q # 38) What does the term “Monkey


Patching” refer to in Python?

Reply: Monkey Patching refers to


modifying a module at runtime.

Q # 39) What do you mean by "suites" in


Python?
Answer: The group of individual
instructions, thus constituting a
logical block of code, is called
sequences

Example:

If expression Suite Else Suite

Q # 40) What is range () in Python?


Give an example to explain it.

Answer: It is a function to iterate


through a sequence of numbers.

Example:

for var in list (range (10)) Print


(var)

Q # 41) What is the difference between


abs () and fabs ()?

Reply:
abs () is a built-in function that also
works with whole, float, and complex
numbers.

fabs () is defined in math module which


does not work with complex numbers.

Q # 42) Write the output for the


following code:

Coded:

str = “Python is a programming


language” print (str.isalnum ()) str =
“This is Interview Question17” print
(str.isalnum ())
Answer: False

True

Q # 43) What is a from import statement


and write the syntax for it?
Answer: The From statement allows you
to import specific attributes from a
module into a current namespace.

Syntax: from modname import name1 [,


name2 [,… nameN]]

Q # 44) What is the difference between


local () and globals ()?

Answer: local () is accessible in the


function and it returns all the names
accessible locally from that function.

global () returns all the names that


can be accessed globally from this
function.

Q # 45) What is the use of assertions


in Python?

Answer: The Assert statement is used to


evaluate the attached expression. If
the expression is false, then python
raised an AssertionError exception.
Q # 46) What is the difference between
"match" and "search" in Python?

Reply: Match checks for a match at the


start of the string while search checks
for a match anywhere in the string

Q # 47) What is the difference between


a shallow copy and a deep copy?

Answer: Shallow copy is used when a new


instance type is created and keeps
copied values while deep copy stores
already copied values.

Shallow copy makes the program run


faster while deep coy slows it down.

Q # 48) What instruction is used in


Python if the instruction is
syntactically required but no action is
required for the program?

Respond: Success Statement


Example:

If (a> 10) print (“Python”) else pass


Q n ° 49) What does PEP8 refer to?

Answer: PEP8 is a coding convention


which is a set of recommendations on
how to make code more readable.

Q # 50) What are * args and * kwargs?

Answer: They are used to pass a


variable number of arguments to a
function. * args is used to pass a
variable-length argument list without
keywords, while * kwargs is used to
pass a variable-length argument list
with keywords.

You might also like