Behavioral Python Interview Questions & Answers:
1. What is the optional statement used in a try except statement in Python?
There are two optional clauses used in try except statements:
1. Else clause: It is useful for code that must be executed when the try block does not create any exception
2. Finally clause: It is useful for code that must be executed irrespective of whether an exception is generated or not.
2. What is used to create Unicode string in Python?
Add u before the string
>>> u 'test'
3. What are the uses of List Comprehensions feature of Python?
List comprehensions help to create and manage lists in a simpler and clearer way than using map(), filter() and lambda. Each list comprehension consists of an expression followed by a clause, then zero or more for or if clauses.
4. What is all the operating system that Python can run on?
Python can run of every operating system like UNIX/LINUX, Mac, Windows, and others.
Pass is a no-operation/action statement in python
If we want to load a module and if it does not exist, let us not bother, let us try to do other task. The following example demonstrates that.
Try:
Import module1
Except:
Pass
6. How is the Implementation of Pythons dictionaries done?
Using curly brackets -> {}
E.g.: {'a':'123', 'b':'456'}
7. Does python support switch or case statement in Python? If not what is the reason for the same?
No. You can use multiple if-else, as there is no need for this.
8. What is the method does join() in python belong?
String method
10. What is the language from which Python has got its features or derived its features?
Most of the object oriented programming languages to name a few are C++, CLISP and Java is the language from which Python has got its features or derived its features.
https://InterviewQuestionsAnswers.ORG.