r/pythontips • • Oct 03 '19

71 Python Interview Questions and Answers [New] – Get Ready for Technical Round

Welcome to the second part of DataFlair’s Python Interview Questions and Answer Series. If you are the first time visitor then you must take a quick look at the series –

As I told you, this is the second part, it mainly focuses on intermediates. In all the parts we have divided the questions into below subcategories so that it will be easier for you to find the question and answer you are searching for. Also, as per the feedback, this is the best way for Python Interview Preparations. Have a look –

  • Basic Python Interview Questions for Intermediates

  • Top Python Interview Questions

  • Python Developer Interview Questions

  • Python OOPS and Library Interview Questions

  • Technical Python Interview Questions and Answers

  • Advanced Python Interview Questions

  • Open-ended Python Interview Questions

Basic Python Interview Questions for Intermediates

Below are some basic python interview questions for intermediates, I recommend you to try to answer them by yourself. If you feel you are not able to answer the question, refer to the answers given by interview experienced.

Q.1. When is the else part of a try-except block executed?

In an if-else block, the else part is executed when the condition in the if-statement is False. But with a try-except block, the else part executes only if no exception is raised in the try part.

Q.2. If a list is nums=[0,1,2,3,4], what is nums[-1]?

This code does not throw an exception. nums[-1] is 4 because it begins traversing from right

Q.3. What is the PYTHONPATH variable?

PYTHONPATH is the variable that tells the interpreter where to locate the module files imported into a program. Hence, it must include the Python source library directory and the directories containing Python source code. You can manually set PYTHONPATH, but usually, the Python installer will preset it.

Read More

73 Upvotes

9 comments sorted by

2

u/bbatwork Oct 03 '19

The answer to #7 is incorrect.
Yes it will be 2, but the reason is there are 2 elements to the original list, not because of the length of the strings.

1

u/Aakashdata Oct 04 '19

Thanks for the the correction

3

u/welpfish Oct 03 '19

came here to say the same:

>>> x = ['ab', 'cd']
>>> print(len(list(map(list, x))))
2
>>> y = ['ab', 'cdefg']
>>> print(len(list(map(list, x))))
2

10

u/robertlf Oct 03 '19

I can't believe all the bullshit programmers are subject to when trying to get a job these days. What's worse is that the people asking the questions only know the answers because the Googled the questions and answers beforehand.

2

u/bbatwork Oct 03 '19

Q24 can also be done with s1=s.replace(' ','')

1

u/FrumunduhCheese Oct 03 '19

Omg I'll never be a programmer. This is motivation killing lol.

1

u/objectech Oct 03 '19

I thought I was still considered a beginner, but I actually think I could qualify for a job after reading this. Self-taught hobbyist over about 1.5 yrs!

1

u/_RouteThe_Switch Oct 03 '19

Agreed these are not too bad, self.taught 4 years in here

1

u/spitfiredd Oct 03 '19

Q9? Really??