Python Interview Questions
1 .
Write a reg expression that confirms an email id using the python reg expression module “re”?
Python has a regular expression module “re.”
Check out the “re” expression that can check the email id for .com and subdomain.
import re
2 .
What is “Call by Value” in Python?
In call-by-value, the argument whether an expression or a value gets bound to the respective variable in the function.
Python will treat that variable as local in the function-level scope. Any changes made to that variable will remain local and will not reflect outside the function.
3 .
What is “Call by Reference” in Python?
We use both “call-by-reference” and “pass-by-reference” interchangeably. When we pass an argument by reference, then it is available as an implicit reference to the function, rather than a simple copy. In such a case, any modification to the argument will also be visible to the caller.
This scheme also has the advantage of bringing more time and space efficiency because it leaves the need for creating local copies.
On the contrary, the disadvantage could be that a variable can get changed accidentally during a function call. Hence, the programmers need to handle in the code to avoid such uncertainty.
4 .
What is the purpose of id() function in Python?
The id() is one of the built-in functions in Python.
Signature: id(object)
It accepts one parameter and returns a unique identifier associated with the input object.
5 .
What is the purpose of “end” in Python?
Python’s print() function always prints a newline in the end. The print() function accepts an optional parameter known as the ‘end.’ Its value is ‘\n’ by default. We can change the end character in a print statement with the value of our choice using this parameter.
# Example: Print a  instead of the new line in the end.
print("Let's learn" , end = ' ')  

# Printing a dot in the end.
print("Learn to code from freetimelearn" , end = '.')  
print("com", end = ' ')
Output :
Let's learn Python
Learn to code from
6 .
When should you use the “break” in Python?
Python provides a break statement to exit from a loop. Whenever the break hits in the code, the control of the program immediately exits from the body of the loop.
The break statement in a nested loop causes the control to exit from the inner iterative block.
7 .
What is Rstrip() in Python?
Python provides the rstrip() method which duplicates the string but leaves out the whitespace characters from the end.
The rstrip() escapes the characters from the right end based on the argument value, i.e., a string mentioning the group of characters to get excluded.
The signature of the rstrip() is :
str.rstrip([char sequence/pre>
test_str = 'Programming    '
# The trailing whitespaces are excluded
8 .
What is Inheritance in Python programming?
Inheritance is used to specify that one class will get most or all of its features from its parent class. It is a feature of Object Oriented Programming. The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class.
The child class or derived class inherits the features from the parent class, adding new features to it. It facilitates re-usability of code.
9 .
What is the syntax for List comprehension in Python?
The signature for the list comprehension is as follows :
[ expression(var) for var in iterable ]

For example, the below code will return all the numbers from 10 to 20 and store them in a list.
>>> alist = [var for var in range(10, 20)]
>>> print(alist)
10 .
What are the different methods to copy an object in Python?
There are two ways to copy objects in Python.
copy.copy() function :
* It makes a copy of the file from source to destination.
* It’ll return a shallow copy of the parameter.

copy.deepcopy() function :
* It also produces the copy of an object from the source to destination.
* It’ll return a deep copy of the parameter that you can pass to the function.