June 2, 2019

Srikaanth

Intelenet Global Services Python Interview Questions

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.
Intelenet Global Services Most Frequently Asked Python Latest Interview Questions Answers
Intelenet Global Services Most Frequently Asked Python Latest Interview Questions Answers

What Are The Optional Statements That Can Be Used Inside A <Try-Except> Block In Python?

There are two optional clauses you can use in the <try-except> block.

The <else> clause
It is useful if you want to run a piece of code when the try block doesn’t create any exception.
The <finally> clause
It is useful when you want to execute some steps which run, irrespective of whether there occurs an exception or not.

How Does The Ternary Operator Work In Python?

The ternary operator is an alternative for the conditional statements. It combines of the true or false values with a statement that you need to test. The syntax would look like the one given below.

[onTrue] if [Condition] else [onFalse]

x, y = 35, 75
smaller = x if x < y else y
print(smaller)

What Does The <Self> Keyword Do?

The <self> keyword is a variable that holds the instance of an object. In almost, all the object-oriented languages, it is passed to the methods as hidden parameter.

 What Are 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.

What Is The Purpose Of Doc Strings In Python?

In Python, documentation string is popularly known as doc strings. It sets a process of recording Python functions, modules, and classes.

Which Python Function Will You Use To Convert A Number To A String?

For converting a number into a string, you can use the built-in function <str()>.  If you want an octal or hexadecimal representation, use the inbuilt function <oct()> or <hex()>.

 How Do You Debug A Program In Python? Is It Possible To Step Through Python Code?

Yes, we can use the Python debugger (<pdb>) to debug any Python program. And if we start a program using <pdb>, then it let us even step through the code.

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’).

https://mytecbooks.blogspot.com/2018/10/intelenet-global-services-most.html
Subscribe to get more Posts :