Juniper Networks Most Frequently Asked Python Latest Interview Questions Answers
How Do I Copy An Object In Python?
In general, try copy.copy() or copy.deepcopy() for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a copy() method:
newdict = olddict.copy()
Sequences can be copied by slicing:
new_l = l[:]
What Are The Built-In Types Available In Python?
Here is the list of most commonly used built-in types that Python supports:
Immutable built-in types of Python
Numbers
Strings
Tuples
Mutable built-in types of Python
List
Dictionaries
Sets
How To Find Bugs Or Perform Static Analysis In A Python Application?
You can use PyChecker, which is a static analyzer. It identifies the bugs in Python project and also reveals the style and complexity related bugs.
Another tool is Pylint, which checks whether the Python module satisfies the coding standard.
When Is The Python Decorator Used?
Python decorator is a relative change that you do in Python syntax to adjust the functions quickly.
What Is The Key Difference Between A List And The Tuple?
List Vs Tuple.
The major difference between a list and the tuple is that the list is mutable while tuple is not. A tuple is allowed to be hashed, for example, using it as a key for dictionaries.
How Does Python Handle The Memory Management?
Python uses private heaps to maintain its memory. So the heap holds all the Python objects and the data structures. This area is only accessible to the Python interpreter; programmers can’t use it.
And it’s the Python memory manager that handles the Private heap. It does the required allocation of the heap for Python objects.
Python employs a built-in garbage collector, which salvages all the unused memory and offloads it to the heap space.
What Are The Principal Differences Between The Lambda And Def?
Lambda Vs Def.
def can hold multiple expressions while lambda is a uni-expression function.
def generates a function and designates a name so as to call it later. lambda forms a function and returns the function itself.
def can have a return statement. lambda can’t have return statements
lambda supports to get used inside a list and dictionary.
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 .co.in subdomain.
import re
print(re.search(r"[0-9a-zA-Z.]+@[a-zA-Z]+\.(com|co\.in)$","micheal.pages@mp.com"))
What Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?
list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
The result of the above lines of code is []. There won’t be any error like an IndexError.
You should know that trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError. By the way, retrieving only a slice at an opening index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.
Is There A Switch Or Case Statement In Python? If Not Then What Is The Reason For The Same?
No, Python does not have a Switch statement, but you can write a Switch function and then use it.
What Is A Built-In Function That Python Uses To Iterate Over A Number Sequence?
range() generates a list of numbers, which is used to iterate over for loops.
for i in range(5):
print(i)
The range() function accompanies two sets of parameters.
range(stop)
stop: It is the no. of integers to generate and starts from zero. eg. range(3) == [0, 1, 2].
range([start], stop[, step])
start: It is the starting no. of the sequence.
stop: It specifies the upper limit of the sequence.
step: It is the incrementing factor for generating the sequence.
Points to note:
Only integer arguments are allowed.
Parameters can be positive or negative.
The <range()> function in Python starts from the zeroth index.
What is the output of print str[2:5] if str = ‘Hello World!’?
It will print characters starting from 3rd to 5th. Output would be llo.
What is the output of print str[2:] if str = ‘Hello World!’?
It will print characters starting from 3rd character. Output would be llo World!.
What is the output of print str * 2 if str = ‘Hello World!’?
It will print string two times. Output would be Hello World!Hello World!.
What is the output of print str + “TEST” if str = ‘Hello World!’?
It will print concatenated string. Output would be Hello World!TEST.
What is the output of print tuple[1:3] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print elements starting from 2nd till 3rd. Output would be (786, 2.23).
What is the output of print tuple[2:] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print elements starting from 3rd element. Output would be (2.23, ‘john’, 70.200000000000003).
What is the output of print tinytuple * 2 if tinytuple = (123, ‘john’)?
It will print tuple two times. Output would be (123, ‘john’, 123, ‘john’).
What is the output of print tuple + tinytuple if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2) and tinytuple = (123, ‘john’)?
It will print concatenated tuples. Output would be (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003, 123, ‘john’).
How Do I Copy An Object In Python?
In general, try copy.copy() or copy.deepcopy() for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a copy() method:
newdict = olddict.copy()
Sequences can be copied by slicing:
new_l = l[:]
What Are The Built-In Types Available In Python?
Here is the list of most commonly used built-in types that Python supports:
Immutable built-in types of Python
Numbers
Strings
Tuples
Mutable built-in types of Python
List
Dictionaries
Sets
Juniper Networks Most Frequently Asked Python Latest Interview Questions Answers |
How To Find Bugs Or Perform Static Analysis In A Python Application?
You can use PyChecker, which is a static analyzer. It identifies the bugs in Python project and also reveals the style and complexity related bugs.
Another tool is Pylint, which checks whether the Python module satisfies the coding standard.
When Is The Python Decorator Used?
Python decorator is a relative change that you do in Python syntax to adjust the functions quickly.
What Is The Key Difference Between A List And The Tuple?
List Vs Tuple.
The major difference between a list and the tuple is that the list is mutable while tuple is not. A tuple is allowed to be hashed, for example, using it as a key for dictionaries.
How Does Python Handle The Memory Management?
Python uses private heaps to maintain its memory. So the heap holds all the Python objects and the data structures. This area is only accessible to the Python interpreter; programmers can’t use it.
And it’s the Python memory manager that handles the Private heap. It does the required allocation of the heap for Python objects.
Python employs a built-in garbage collector, which salvages all the unused memory and offloads it to the heap space.
What Are The Principal Differences Between The Lambda And Def?
Lambda Vs Def.
def can hold multiple expressions while lambda is a uni-expression function.
def generates a function and designates a name so as to call it later. lambda forms a function and returns the function itself.
def can have a return statement. lambda can’t have return statements
lambda supports to get used inside a list and dictionary.
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 .co.in subdomain.
import re
print(re.search(r"[0-9a-zA-Z.]+@[a-zA-Z]+\.(com|co\.in)$","micheal.pages@mp.com"))
What Do You Think Is The Output Of The Following Code Fragment? Is There Any Error In The Code?
list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
The result of the above lines of code is []. There won’t be any error like an IndexError.
You should know that trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError. By the way, retrieving only a slice at an opening index that surpasses the no. of items in the list won’t result in an IndexError. It will just return an empty list.
Is There A Switch Or Case Statement In Python? If Not Then What Is The Reason For The Same?
No, Python does not have a Switch statement, but you can write a Switch function and then use it.
What Is A Built-In Function That Python Uses To Iterate Over A Number Sequence?
range() generates a list of numbers, which is used to iterate over for loops.
for i in range(5):
print(i)
The range() function accompanies two sets of parameters.
range(stop)
stop: It is the no. of integers to generate and starts from zero. eg. range(3) == [0, 1, 2].
range([start], stop[, step])
start: It is the starting no. of the sequence.
stop: It specifies the upper limit of the sequence.
step: It is the incrementing factor for generating the sequence.
Points to note:
Only integer arguments are allowed.
Parameters can be positive or negative.
The <range()> function in Python starts from the zeroth index.
What is the output of print str[2:5] if str = ‘Hello World!’?
It will print characters starting from 3rd to 5th. Output would be llo.
What is the output of print str[2:] if str = ‘Hello World!’?
It will print characters starting from 3rd character. Output would be llo World!.
What is the output of print str * 2 if str = ‘Hello World!’?
It will print string two times. Output would be Hello World!Hello World!.
What is the output of print str + “TEST” if str = ‘Hello World!’?
It will print concatenated string. Output would be Hello World!TEST.
What is the output of print tuple[1:3] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print elements starting from 2nd till 3rd. Output would be (786, 2.23).
What is the output of print tuple[2:] if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2 )?
It will print elements starting from 3rd element. Output would be (2.23, ‘john’, 70.200000000000003).
What is the output of print tinytuple * 2 if tinytuple = (123, ‘john’)?
It will print tuple two times. Output would be (123, ‘john’, 123, ‘john’).
What is the output of print tuple + tinytuple if tuple = ( ‘abcd’, 786 , 2.23, ‘john’, 70.2) and tinytuple = (123, ‘john’)?
It will print concatenated tuples. Output would be (‘abcd’, 786, 2.23, ‘john’, 70.200000000000003, 123, ‘john’).
Post a Comment