eInterviewQuestions

Python Interviews Questions

All our users, you can also add/post your question and answer which is mostly asked by an Interviewer in Interviews, you all can suggest for any changes to make our website best & user friendly. please feel free to Post Question.

Q1. What is Python ? What are the benefits of using Python?

Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. 

Platforms Support

It runs on many Unix  variants, on the Mac, and on PCs under MS-DOS, Windows, Windows NT, and OS/2. 

Python is a high-level, interpreted, interactive and object-oriented scripting language which finds its application in many areas like -

1. Webscripting

2. 3d Modelling (Blender)

3. Desktop Applications -`Games (Pygame)

4. Scientific usage (SciPy/NumPy)

5. Python source code is available under the GNU General Public License (GPL). There are two major Python versions, Python2 and Python3.

Python features

1. Open Source and Simple to use

2. Very powerful and Ubiquitous

3. Supports broad standard library

4. Supports interactive testing and debugging

5. Established interface with all major DB's

6. Runs on variety of hardware platforms

Technical features of Python

1. Object-oriented (supports both functional and structured programming)

2. Dynamically and strongly typed

3. Whitespace delimited (Indentation)

4. Scripting language which supports large applications.

5. High-level dynamic data types and supports dynamic type checking

6. Automatic garbage collection

7. Interpreted makes compiler interact with developer.

8. Easy integration with C, C++, COM, ActiveX, CORBA and Java.

Python Implementations

CPython - Python implementation on standard C language.

Jython - Python implementation with Java virtual machine to blend with Java.

Pypy - Python implemented in Python and its Just-in time compiler making it fastest.

Iron Python - for windows, which implements common runtime libraries to interface with .NET.


Q2. Difference between Python2 & Python3

Python 2 treats “print” as statement rather a function.

Python 2 treats numbers without any digits. (Output of expression 3 / 2 is 1, not 1.5). To get the result 1.5, you would have to write 3.0 / 2.0.

Python 2:raise IOError, “some error message”

 

Python 3 explicitly treats “print” as a function.

Python 3 evaluates 3 / 2 as 1.5 by default, which is more intuitive for new programmers.

Python3: raise IOError(“some error message”)


Q3. What is the purpose of PYTHONPATH environment variable?

PYTHONPATH − It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer


Q4. What is the purpose of PYTHONSTARTUP,PYTHONCASEOK,PYTHONHOME,PYTHONSTARTUP environment variables?

PYTHONSTARTUP − It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH

PYTHONCASEOK − It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.

PYTHONHOME − It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.


Q5. Data types in Python?

Numbers

String

List

Tuple

Dictionary


Q6. Difference between list and tuples?

LIST

The literal syntax of lists is shown by square brackets []

Lists are mutable i.e they can be edited.

Lists are slower than tuples.

Lists are for variable length

Lists are homogeneous sequences

Syntex : dDaysList = ["sunday", "monday", "tuesday"]

TUPLES

The literal syntax of tuples is shown by parentheses {}

Tuples are immutable (tuples are lists which can’t be edited).

Tuples are faster than list.

tuples are for fixed length.

Tuples are heterogeneous data structures (i.e., their entries have different meanings)

syntex : dDaysTuple = ("sunday", "monday", "tuesday")