Python interview question 2022
Q.1) why python known as interpreted language?
Ø Because
its code can be converted directly into machine code. It does not require any
compiler.
Q.2) python tools that help to
find bugs?
Ø pylint
tools that help to find bugs.
Q.3) why the pass statement is used in python?
Ø Pass statement is used when a statement is required syntactically but we do not want
any code to execute.
Q.4) what are iterators in python?
Ø It
is an object that contains countable numbers of values and all these values can be traversed using for loop(and many other ways)
Q.5) how a number can be
converted into a string using python?
Ø str(number)
Q.6) how random numbers can be
generated in python?
import <random>
# module
Q.7) what are the 5 benefits of
using python?
1.
Easy to learn
2.
Interpreted language
3.
Large library
4.
OOPs based
5.
Portable
Q.8) what is the difference
between Django and flask?
Django:- in
Django all configuration and basic structure is already provided so less work
Flask:- flask to do while in flask everything needs
to do. From scratch
Q.9) python is case sensitive?
Ø Yes
python is case sensitive
Q.10) what is the difference
between python arrays and Python lists?
Ø Python
list:- list can
contain heterogeneous types of data.
Ø Python
array:- array
contains homogeneous data.
Q.11) what is self in python?
Ø It’s
a reference variable which refers to the current object
Q.12) difference between NumPy
and lists?
Ø Python
list:- list can
contain a heterogeneous type of data.
Ø Python
NumPy:- array
contains homogeneous data.
Q.13) does python-support
multiple inheritances?
Ø Yes
python-support multiple inheritances
Q.14) use of help() and dir()
function in python?
Ø help():- help() function display documentation of a modules, function classes
keywords
Ø dir():- returns all properties and methods of a specified object without values.
Q.15) what is slicing in python
Example?
Example:- a=(‘a’,
‘b’, ‘c’, ‘d’,
‘e’, ‘f’, ‘g’,
‘h’, ‘I’)
Print(a[2:5])
Output:- (
‘c’, ‘d’, ‘e’, )
Q.16) how to declare a comment
in Python?
Ø Single
line comment- #
Ø Multiline
comment- ‘’’ programming khata’’’ /
“””programming khata”””
Q.17) which function is used to
check if all characters in a String are alphanumeric in python?
Ø isalnum()
function
Q.18) how to capitalize the first
letter of a string in python?
Ø capitalize() function
Q.19) how to reverse a list in
python? Don’t use an inbuilt function?
a = “programming
khata”
print(a[:: -1])
Q.20) IDEs available for python?
Ø Pychram,
inteliJ, VScode, IDLE, etc..
Q.21) how duplicate elements
can be removed from a list?
Ø Convert
the list into a set because the set does not contain duplicate items.
Q.22) why data types are supported
by python?
Ø Str,
set, list, dict, tuple, Boolean, float,
none
Q.23) What is PEP8 in python?
Ø It is
a document that provides guidelines and best practices on how to write python
code.
Q.24) difference between java
& python?
Java is statically typed
Python is dynamically typed
Q.25) if n =
[9, 7, 4, 2] n = [-2] = ??
Ø 4
Q.26) Write code to remove
white space from ‘a b c d’ using python?
a = ‘a b c d’
a.replace(“ “,””)
Q.27) difference between deep copy and shallow copy in python?
Ø Shalowcopy:- creates a new object which stores the
reference of the original elements.
Ø Deepcopy:- creates a new object and recursively adds the
copies of nested objects present in the original,
Q.28) method vs constructor in python?
Ø Constructor:- is
used to initialize an object
Ø Method:- is used
to exhibits functionality of an object
Q.29) write a function name to
declare a file from python?
Ø os.removed ()
function
Q.30) if a>b:
print(a)
else:
print(b)
Write this code using lambda function?
lambda a,b: a if
a>b
else b
0 Comments