Python_Interview_Questions_For_Freshers
Python_Interview_Questions_For_Freshers
Its high-level data structures, combined with dynamic typing and dynamic
binding, attract a huge community of developers for Rapid Application
Development and deployment.
Note: Local scope objects can be synced with global scope objects using
keywords such as global.
6. What are lists and tuples? What is the key difference between the
two?
Lists and Tuples are both sequence data types that can store a collection of
objects in Python. The objects stored in both sequences can have different
data types. Lists are represented with square brackets ['sara', 6, 0.19],
while tuples are represented with parantheses ('ansh', 5, 0.97).
But what is the real difference between the two? The key difference between
the two is that while lists are mutable, tuples on the other hand
are immutable objects. This means that lists can be modified, appended or
sliced on the go but tuples remain constant and cannot be modified in any
manner. You can run the following example on Python IDLE to confirm the
difference:
There are several built-in data types in Python. Although, Python doesn't
require data types to be defined explicitly during variable declarations type
errors are likely to occur if the knowledge of data types and their
compatibility with each other are neglected. Python
provides type() and isinstance() functions to check the type of these
variables. These data types can be grouped into the following categories-
• None Type:
None keyword represents the null values in Python. Boolean equality
operation can be performed using these NoneType objects.
Class Name Description
NoneType Represents the NULL values in Python.
• Numeric Types:
There are three distinct numeric types - integers, floating-point
numbers, and complex numbers. Additionally, booleans are a sub-
type of integers.
• Sequence Types:
According to Python Docs, there are three basic Sequence Types
- lists, tuples, and range objects. Sequence types have the in and not
in operators defined for their traversing their elements. These
operators share the same priority as the comparison operations.
Note: The standard library also includes additional types for processing:
1. Binary data such as bytearray bytes memoryview , and
2. Text strings such as str.
• Mapping Types:
A mapping object can map hashable values to random objects in Python.
Mappings objects are mutable and there is currently only one standard
mapping type, the dictionary.
• Set Types:
Currently, Python has two built-in set types
- set and frozenset. set type is mutable and supports methods
like add() and remove(). frozenset type is immutable and can't be
modified after creation.
Note: set is mutable and thus cannot be used as key for a dictionary. On
the other hand, frozenset is immutable and thus, hashable, and can be used
as a dictionary key or as an element of another set.
• Modules:
Module is an additional built-in type supported by the Python
Interpreter. It supports one special operation, i.e., attribute
access: mymod.myobj, where mymod is a module
and myobj references a name defined in m's symbol table. The
module's symbol table resides in a very special attribute of the
module __dict__, but direct assignment to this module is neither
possible nor recommended.
• Callable Types:
Callable types are the types to which function call can be applied.
They can be user-defined functions, instance methods, generator
functions, and some other built-in functions, methods and classes.
Refer to the documentation at docs.python.org for a detailed view of
the callable types.
# do nothing
pass
Python packages and Python modules are two mechanisms that allow
for modular programming in Python. Modularizing has several
advantages -
Modules, in general, are simply Python files with a .py extension and can
have a set of functions, classes, or variables defined and implemented.
They can be imported and initialized once using the import statement. If
partial functionality is needed, import the requisite classes or functions
using from foo import bar.
Packages allow for hierarchial structuring of the module namespace
using dot notation. As, modules help avoid clashes between global
variable names, in a similar manner, packages help avoid clashes between
module names.
Creating a package is easy since it makes use of the system's inherent file
structure. So just stuff the modules into a folder and there you have it, the
folder name as the package name. Importing a module or its contents from
this package requires the package name as prefix to the module name
joined by a dot.
• Global variables are public variables that are defined in the global
scope. To use the variable in the global scope inside a function, we
use the global keyword.
• Protected attributes are attributes defined with an underscore
prefixed to their identifier eg. _sara. They can still be accessed and
modified from outside the class they are defined in but a responsible
developer should refrain from doing so.
• Private attributes are attributes with double underscore prefixed to
their identifier eg. __ansh. They cannot be accessed or modified
from the outside directly and will result in an AttributeError if such
an attempt is made.
Self is used to represent the instance of the class. With this keyword, you
can access the attributes and methods of the class in python. It binds the
attributes with the given arguments. self is used in different places and
often thought to be a keyword. But unlike in C++, self is not a keyword in
Python.
# class definition
class Student:
self.firstname = fname
self.lastname = lname
self.age = age
self.section = section
Break : The break statement terminates the loop immediately and the
control flows to the statement after the body of the loop.
pat = [1, 3, 2, 1, 2, 3, 1, 0, 1, 3]
for p in pat:
pass
if (p == 0): pat = [1, 3, 2, 1, 2, 3, 1, 0, 1, 3]
for p in pat:
pass
if (p == 0):
current = p
break
elif (p % 2 == 0):
continue
print(p) # output => 1 3 1 3 1
print(current) # output => 0
current = p
break
elif (p % 2 == 0):
continue
print(p) # output => 1 3 1 3 1
Example:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(numbers[1 : : 2]) #output : [2, 4, 6, 8, 10]
17. Explain how can you make a Python Script executable on Unix?
• Arrays in python can only contain elements of same data types i.e.,
data type of array should be homogeneous. It is a thin wrapper around
C language arrays and consumes far less memory than lists.
• Lists in python can contain elements of different data types i.e., data
type of lists can be heterogeneous. It has the disadvantage of
consuming large memory.
import array
a = array.array('i', [1, 2, 3])
for i in a:
print(i, end=' ') #OUTPUT: 1 2 3
a = array.array('i', [1, 2, 'string']) #OUTPUT: TypeError: an integer is
required (got type str)
a = [1, 2, 'string']
for i in a:
print(i, end=' ') #OUTPUT: 1 2 string
Python Interview Questions for Experienced
1. How is memory managed in Python?
A namespace in Python ensures that object names in a program are unique and
can be used without any conflict. Python implements these namespaces as
dictionaries with 'name as key' mapped to a corresponding 'object as value'. This
allows for multiple namespaces to use the same name and map it to a separate
object. A few examples of namespaces are as follows:
Sometimes objects within the same scope have the same name but function
differently. In such cases, scope resolution comes into play in Python
automatically. A few examples of such behavior are:
• Python modules namely 'math' and 'cmath' have a lot of functions that are
common to both of them - log10(), acos(), exp() etc. To resolve this ambiguity,
it is necessary to prefix them with their respective module,
like math.exp() and cmath.exp().
• Consider the code below, an object temp has been initialized to 10 globally
and then to 20 on function call. However, the function call didn't change
the value of the temp globally. Here, we can observe that Python draws a
clear line between global and local variables, treating their namespaces as
separate identities.
Example:
temp = 10 # global-scope variable
def func():
temp = 20 # local-scope variable
print(temp)
print(temp) # output => 10
func() # output => 20
This behavior can be overridden using the global keyword inside the
function, as shown in the following example:
The beauty of the decorators lies in the fact that besides adding
functionality to the output of the method, they can even accept
arguments for functions and can further modify those arguments before
passing it to the function itself. The inner nested function, i.e. 'wrapper'
function, plays a significant role here. It is implemented to
enforce encapsulation and thus, keep itself hidden from the global scope.
a = [1, 2, 3]
b = [7, 8, 9]
[(x + y) for (x,y) in zip(a,b)] # parallel iterators
# output => [8, 10, 12]
[(x,y) for x in a for y in b] # nested iterators
# output => [(1, 7), (1, 8), (1, 9), (2, 7), (2, 8), (2, 9), (3, 7), (3, 8), (3, 9)]
my_list = [[10,20,30],[40,50,60],[70,80,90]]
flattened = [x for temp in my_list for x in temp]
# output => [10, 20, 30, 40, 50, 60, 70, 80, 90]
Note: List comprehensions have the same effect as the map method in
other languages. They follow the mathematical set builder notation rather
than map and filter functions in Python.
mul = lambda a, b : a * b
print(mul(2, 5)) # output => 10
def myWrapper(n):
return lambda a : a * n
mulFive = myWrapper(5)
print(mulFive(2)) # output => 10
xrange() and range() are quite similar in terms of functionality. They both
generate a sequence of integers, with the only difference
that range() returns a Python list, whereas, xrange() returns an xrange
object.
So how does that make a difference? It sure does, because unlike range(),
xrange() doesn't generate a static list, it creates the value on the go. This
technique is commonly used with an object-type generator and has been
termed as "yielding".
Note: xrange has been deprecated as of Python 3.x. Now range does
exactly the same as what xrange used to do in Python 2.x, since it was way
better to use xrange() than the original range() function in Python 2.x.
Pickling:
Unpickling:
• .py files contain the source code of a program. Whereas, .pyc file
contains the bytecode of your program. We get bytecode after
compilation of .py file (source code). .pyc files are not created for all
the files that you run. It is only created for the files that you import.
• Before executing a python program python interpreter checks for the
compiled files. If the file is present, the virtual machine executes it. If
not found, it checks for .py file. If found, compiles it to .pyc file and
then python virtual machine executes it.
• Having .pyc file saves you the compilation time.
def appendNumber(arr):
arr.append(4)
arr = [1, 2, 3]
print(arr) #Output: => [1, 2, 3]
appendNumber(arr)
print(arr) #Output: => [1, 2, 3, 4]
• An iterator is an object.
• It remembers its state i.e., where it is during iteration (see code below
to see how)
• __iter__() method initializes an iterator.
• It has a __next__() method which returns the next item in iteration and
points to the next element. Upon reaching the end of iterable object
__next__() must return StopIteration exception.
• It is also self-iterable.
• Iterators are objects with which we can iterate over iterable objects
like lists, strings, etc.
class ArrayList:
def __init__(self, number_list):
self.numbers = number_list
def __iter__(self):
self.pos = 0
return self
def __next__(self):
if(self.pos < len(self.numbers)):
self.pos += 1
return self.numbers[self.pos - 1]
else:
raise StopIteration
array_obj = ArrayList([1, 2, 3])
it = iter(array_obj)
print(next(it)) #output: 2
print(next(it)) #output: 3
print(next(it))
#Throws Exception
#Traceback (most recent call last):
#...
#StopIteration
import os
os.remove("ChangedFile.csv")
print("File Removed!")
*args
**kwargs
def tellArguments(**kwargs):
for key, value in kwargs.items():
print(key + ": " + value)
tellArguments(arg1 = "argument 1", arg2 = "argument 2", arg3 = "argument
3")
#output:
# arg1: argument 1
# arg2: argument 2
# arg3: argument 3
20. What are negative indexes and why are they used?
• Negative indexes are the indexes from the end of the list or tuple or
string.
• Arr[-1] means the last element of array Arr[]
arr = [1, 2, 3, 4, 5, 6]
#get the last element
print(arr[-1]) #output 6
#get the second last element
print(arr[-2]) #output 5
Python OOPS Interview Questions
1. How do you create a class in Python?
class InterviewbitEmployee:
def __init__(self, emp_name):
self.emp_name = emp_name
emp_1=InterviewbitEmployee("Mr. Employee")
To access the name attribute, we just call the attribute using the dot
operator as shown below:
print(emp_1.emp_name)
# Prints Mr. Employee
To create methods inside the class, we include the methods under the scope
of the class as shown below:
class InterviewbitEmployee:
def __init__(self, emp_name):
self.emp_name = emp_name
def introduce(self):
print("Hello I am " + self.emp_name)
The self parameter in the init and introduce functions represent the
reference to the current class instance which is used for accessing attributes
and methods of that class. The self parameter has to be the first parameter
of any method defined inside the class. The method of the class
InterviewbitEmployee can be accessed as shown below:
emp_1.introduce()
class InterviewbitEmployee:
def __init__(self, emp_name):
self.emp_name = emp_name
def introduce(self):
print("Hello I am " + self.emp_name)
Inheritance gives the power to a class to access all attributes and methods
of another class. It aids in code reusability and helps the developer to
maintain applications without redundant code. The class inheriting from
another class is a child class or also called a derived class. The class from
which a child class derives the members are called parent class or
superclass.
Example:
# Parent class
class ParentClass:
def par_func(self):
print("I am parent class function")
# Child class
class ChildClass(ParentClass):
def child_func(self):
print("I am child class function")
# Driver code
obj1 = ChildClass()
obj1.par_func()
obj1.child_func()
Example:
# Parent class
class A:
def __init__(self, a_name):
self.a_name = a_name
# Intermediate class
class B(A):
def __init__(self, b_name, a_name):
self.b_name = b_name
# invoke constructor of class A
A.__init__(self, a_name)
# Child class
class C(B):
def __init__(self,c_name, b_name, a_name):
self.c_name = c_name
# invoke constructor of class B
B.__init__(self, b_name, a_name)
def display_names(self):
print("A name : ", self.a_name)
print("B name : ", self.b_name)
print("C name : ", self.c_name)
# Driver code
obj1 = C('child', 'intermediate', 'parent')
print(obj1.a_name)
obj1.display_names()
Example:
# Parent class1
class Parent1:
def parent1_func(self):
print("Hi I am first Parent")
# Parent class2
class Parent2:
def parent2_func(self):
print("Hi I am second Parent")
# Child class
class Child(Parent1, Parent2):
def child_func(self):
self.parent1_func()
self.parent2_func()
# Driver's code
obj1 = Child()
obj1.child_func()
Example:
# Base class
class A:
def a_func(self):
print("I am from the parent class.")
# Driver's code
obj1 = B()
obj2 = C()
obj1.a_func()
obj1.b_func() #child 1 method
obj2.a_func()
Following are the ways using which you can access parent class members
within a child class:
• By using Parent class name: You can use the name of the parent
class to access the attributes as shown in the example below:
class Parent(object):
# Constructor
def __init__(self, name):
self.name = name
class Child(Parent):
# Constructor
def __init__(self, name, age):
Parent.name = name
self.age = age
def display(self):
print(Parent.name, self.age)
# Driver Code
obj = Child("Interviewbit", 6)
obj.display()
• By using super(): The parent class members can be accessed in child
class using the super keyword.
class Parent(object):
# Constructor
def __init__(self, name):
self.name = name
class Child(Parent):
# Constructor
def __init__(self, name, age):
'''
In Python 3.x, we can also use super().__init__(name)
'''
super(Child, self).__init__(name)
self.age = age
def display(self):
# Note that Parent.name cant be used
# here since super() is used in the constructor
print(self.name, self.age)
# Driver Code
obj = Child("Interviewbit", 6)
obj.display()
Python does not make use of access specifiers specifically like private,
public, protected, etc. However, it does not derive this from any variables.
It has the concept of imitating the behaviour of variables by making use of
a single (protected) or double underscore (private) as prefixed to the
variable names. By default, the variables without prefixed underscores are
public.
Example:
# protected members
_emp_name = None
_age = None
# private members
__branch = None
# constructor
def __init__(self, emp_name, age, branch):
self._emp_name = emp_name
self._age = age
self.__branch = branch
#public member
def display():
print(self._emp_name +" "+self._age+" "+self.__branch)
An empty class does not have any members defined in it. It is created by
using the pass keyword (the pass command does nothing in python). We
can create objects for this class outside the class.
For example-
class EmptyClassDemo:
pass
obj=EmptyClassDemo()
obj.name="Interviewbit"
print("Name created= ",obj.name)
Output:
Name created = Interviewbit
The new modifier is used to instruct the compiler to use the new
implementation and not the base class function. The Override modifier is
useful for overriding a base class function inside the child class.
The init method works similarly to the constructors in Java. The method is
run as soon as an object is instantiated. It is useful for initializing any
attributes or default behaviour of the object at the time of instantiation.
For example:
class InterviewbitEmployee:
# introduce method
def introduce(self):
print('Hello, I am ', self.emp_name)
class Parent(object):
pass
class Child(Parent):
pass
# Driver Code
print(issubclass(Child, Parent)) #True
print(issubclass(Parent, Child)) #False
• We can check if an object is an instance of a class by making use
of isinstance() method:
obj1 = Child()
obj2 = Parent()
print(isinstance(obj2, Child)) #False
print(isinstance(obj2, Parent)) #True
Python Pandas Interview Questions
1. What do you know about pandas?
import pandas as pd
dataframe = pd.DataFrame( data, index, columns, dtype)
where:
• data - Represents various forms like series, map, ndarray, lists, dict
etc.
• index - Optional argument that represents an index to row labels.
• columns - Optional argument for column labels.
• Dtype - the data type of each column. Again optional.
df1.append(df2)
pd.concat([df1, df2])
• join() method: This is used for extracting data from various
dataframes having one or more common columns.
df1.join(df2)
import pandas as pd
dict_info = {'key1' : 2.0, 'key2' : 3.1, 'key3' : 2.2}
series_obj = pd.Series(dict_info)
print (series_obj)
Output:
x 2.0
y 3.1
z 2.2
dtype: float64
If an index is not specified in the input method, then the keys of the
dictionaries are sorted in ascending order for constructing the index. In
case the index is passed, then values of the index label will be extracted
from the dictionary.
5. How will you identify and deal with missing values in a dataframe?
We can identify if a dataframe has missing values by using the isnull() and
isna() methods.
missing_data_count=df.isnull().sum()
We can handle missing values by either replacing the values in the column
with 0 as follows:
df[‘column_name’].fillna(0)
df[‘column_name’] =
df[‘column_name’].fillna((df[‘column_name’].mean()))
import pandas as pd
data_info = {'first' : pd.Series([1, 2, 3], index=['a', 'b', 'c']),
'second' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(data_info)
#To add new column third
df['third']=pd.Series([10,20,30],index=['a','b','c'])
print (df)
#To add new column fourth
df['fourth']=df['first']+info['third']
print (df)
8. How will you delete indices, rows and columns from a dataframe?
To delete an Index:
Column 1
Names
John 1
Jack 2
Judy 3
Jim 4
df.index.name = None
# Or run the below:
# del df.index.name
print(df)
Column 1
John 1
Jack 2
Judy 3
Jim 4
9. Can you get items of series A that are not available in another series
B?
import pandas as pd
df1 = pd.Series([2, 4, 8, 10, 12])
df2 = pd.Series([8, 12, 10, 15, 16])
df1=df1[~df1.isin(df2)]
print(df1)
"""
Output:
0 2
1 4
dtype: int64
"""
10. How will you get the items that are not common to both the given
series A and B?
We can achieve this by first performing the union of both series, then
taking the intersection of both series. Then we follow the approach of
getting items of union that are not there in the list of the intersection.
import pandas as pd
import numpy as np
df1 = pd.Series([2, 4, 5, 8, 10])
df2 = pd.Series([8, 10, 13, 15, 17])
p_union = pd.Series(np.union1d(df1, df2)) # union of series
p_intersect = pd.Series(np.intersect1d(df1, df2)) # intersection of series
unique_elements = p_union[~p_union.isin(p_intersect)]
print(unique_elements)
"""
Output:
0 2
1 4
2 5
5 13
6 15
7 17
dtype: int64
"""
11. While importing data from different sources, can the pandas
library recognize dates?
Yes, they can, but with some bit of help. We need to add the parse_dates
argument while we are reading data from the sources. Consider an example
where we read data from a CSV file, we may encounter different date-time
formats that are not readable by the pandas library. In this case, pandas
provide flexibility to build our custom date parser with the help of lambda
functions as shown below:
import pandas as pd
from datetime import datetime
dateparser = lambda date_val: datetime.strptime(date_val, '%Y-%m-%d
%H:%M:%S')
df = pd.read_csv("some_file.csv", parse_dates=['datetime_column'],
date_parser=dateparser)
Numpy Interview Questions
1. What do you understand by NumPy?
• The list data structure of python is very highly efficient and is capable
of performing various functions. But, they have severe limitations
when it comes to the computation of vectorized operations which
deals with element-wise multiplication and addition. The python lists
also require the information regarding the type of every element
which results in overhead as type dispatching code gets executes
every time any operation is performed on any element. This is where
the NumPy arrays come into the picture as all the limitations of
python lists are handled in NumPy arrays.
• Additionally, as the size of the NumPy arrays increases, NumPy
becomes around 30x times faster than the Python List. This is because
the Numpy arrays are densely packed in the memory due to their
homogenous nature. This ensures the memory free up is also faster.
• 1D array creation:
import numpy as np
one_dimensional_list = [1,2,4]
one_dimensional_arr = np.array(one_dimensional_list)
print("1D array is : ",one_dimensional_arr)
• 2D array creation:
import numpy as np
two_dimensional_list=[[1,2,3],[4,5,6]]
two_dimensional_arr = np.array(two_dimensional_list)
print("2D array is : ",two_dimensional_arr)
• 3D array creation:
import numpy as np
three_dimensional_list=[[[1,2,3],[4,5,6],[7,8,9]]]
three_dimensional_arr = np.array(three_dimensional_list)
print("3D array is : ",three_dimensional_arr)
import numpy as np
ndArray = np.array([1, 2, 3, 4], ndmin=6)
print(ndArray)
print('Dimensions of array:', ndArray.ndim)
4. You are given a numpy array and a new column as inputs. How will
you delete the second column and replace the column with a new
column value?
Example:
Given array:
[[35 53 63]
[72 12 22]
[43 84 56]]
[
20
30
40
]
Solution:
import numpy as np
#inputs
inputArray = np.array([[35,53,63],[72,12,22],[43,84,56]])
new_col = np.array([[20,30,40]])
# delete 2nd column
arr = np.delete(inputArray , 1, axis = 1)
#insert new_col to array
arr = np.insert(arr , 1, new_col, axis = 1)
print (arr)
We can use the method numpy.loadtxt() which can automatically read the
file’s header and footer lines and the comments if any.
This method is highly efficient and even if this method feels less efficient,
then the data should be represented in a more efficient format such as CSV
etc. Various alternatives can be considered depending on the version of
NumPy used.
• Text files: These files are generally very slow, huge but portable and
are human-readable.
• Raw binary: This file does not have any metadata and is not portable.
But they are fast.
• Pickle: These are borderline slow and portable but depends on the
NumPy versions.
• HDF5: This is known as the High-Powered Kitchen Sink format
which supports both PyTables and h5py format.
• .npy: This is NumPy's native binary data format which is extremely
simple, efficient and portable.
7. How will you sort the array based on the Nth column?
Let us try to sort the rows by the 2nd column so that we get:
[[6, 1, 4],
[8, 3, 2],
[3, 6, 5]]
import numpy as np
arr = np.array([[8, 3, 2],
[3, 6, 5],
[6, 1, 4]])
#sort the array using np.sort
arr = np.sort(arr.view('i8,i8,i8'),
order=['f1'],
axis=0).view(np.int)
We can also perform sorting and that too inplace sorting by doing:
arr.view('i8,i8,i8').sort(order=['f1'], axis=0)
8. How will you find the nearest value in a given numpy array?
import numpy as np
def find_nearest_value(arr, value):
arr = np.asarray(arr)
idx = (np.abs(arr - value)).argmin()
return arr[idx]
#Driver code
arr = np.array([ 0.21169, 0.61391, 0.6341, 0.0131, 0.16541, 0.5645,
0.5742])
value = 0.52
print(find_nearest_value(arr, value)) # Prints 0.5645
9. How will you reverse the numpy array using one line of code?
reversed_array = arr[::-1]
10. How will you find the shape of any given NumPy array?
We can use the shape attribute of the numpy array to find the shape. It
returns the shape of the array in terms of row count and column count of
the array.
import numpy as np
arr_two_dim = np.array([("x1","x2", "x3","x4"),
("x5","x6", "x7","x8" )])
arr_one_dim = np.array([3,2,4,5,6])
# find and print shape
print("2-D Array Shape: ", arr_two_dim.shape)
print("1-D Array Shape: ", arr_one_dim.shape)
"""
Output:
2-D Array Shape: (2, 4)
1-D Array Shape: (5,)
"""
Python Libraries Interview Questions
1. Differentiate between a package and a module in python.
The module is a single python file. A module can import other modules
(other python files) as objects. Whereas, a package is the folder/directory
where different sub-packages and the modules reside.
A python module is created by saving a file with the extension of .py. This
file will have classes and functions that are reusable in the code as well as
across modules.
• Create a directory and give a valid name that represents its operation.
• Place modules of one kind in this directory.
• Create __init__.py file in this directory. This lets python know the
directory we created is a package. The contents of this package can be
imported across different modules in other packages to reuse the
functionality.
Python modules are the files having python code which can be functions,
variables or classes. These go by .py extension. The most commonly
available built-in modules are:
• os
• math
• sys
• random
• re
• datetime
• JSON
import random
print(random.random())
import random
print(random.randrange(5,100,2))
This can be easily done by making use of the isalnum() method that returns
true in case the string has only alphanumeric characters.
For Example -
import re
print(bool(re.match('[A-Za-z0-9]+$','abdc1321'))) # Output: True
print(bool(re.match('[A-Za-z0-9]+$','xyz@123$'))) # Output: False
7. Define PYTHONPATH.
8. Define PIP.
PIP stands for Python Installer Package. As the name indicates, it is used
for installing different python modules. It is a command-line tool providing
a seamless interface for installing different python modules. It searches
over the internet for the package and installs them into the working
directory without the need for any interaction with the user. The syntax for
this is:
9. Are there any tools for identifying bugs and performing static
analysis in python?
Yes, there are tools like PyChecker and Pylint which are used as static
analysis and linting tools respectively. PyChecker helps find bugs in
python source code files and raises alerts for code issues and their
complexity. Pylint checks for the module’s coding standards and supports
different plugins to enable custom features to meet this requirement.
• Shallow copy does the task of creating new objects storing references
of original elements. This does not undergo recursion to create copies
of nested objects. It just copies the reference details of nested objects.
• Deep copy creates an independent and new copy of an object and even
copies all the nested objects of the original element recursively.
def main():
print("Hi Interviewbit!")
if __name__=="__main__":
main()