If you are looking for a Python Developer Jobs, you will need to prepare for a battery of questions that can help you excel at the job interview. Training Basket brings you list of top Python interview questions.

  1. What is the Python programming language? List out key benefits

Python is an object-oriented programming language with modules, threads, exceptions and automatic memory management.

Some of the benefits of using Python are as follows:

  • High-level language.
  • Modular
  • Object Oriented
  • Built-in data structure
  • Open source
  1. How are compile-time and run-time code checking done in Python?

Python has a unique way of performing compile-time and run-time code checking. A small portion checking is carried out during compile-time checking, but most of the checks such as type, name, etc are postponed until code execution. If the Python code references a user-defined function that does not exist, the code will compile successfully and the code will fail with an exception only when the code execution path references the function which does not exist.

  1.  How is Python executed?

Python files are first compiled to bytecode and are then executed by the host. “OR” Type python.pv at the command line.

  1. State how arguments are passed by value or by reference.

d so all variables hold references to the objects. The references values are according to the functions and as a result, the value of references cannot be changed. However, the objects can be changed if it is mutable.

  • What is the difference between .py and .pyc files?

.py files are Python source files. .pyc files are the compiled byte code files that is generated by the Python compiler

6  Explain the use of try: except raise, and finally.

Python makes use of try, except and finally blocks for error handling. Try block is used to execute the code until an error occurs. We can make use of an except block to receive control which will receive control after all errors, or one can use specific exception handling blocks for various error types. Control is transferred to the appropriate except block. In all cases, the final block is executed. Raise may be used to raise your own exceptions.

7  How are instance variables different from class variables?

Instance variables are variables that are created locally within a class to refer to an object of the class. A class variable is one that is created globally in a class and is accessible within all instance of that class.

Class variables are declared with keyword static and Instance variables are declared without static keyword.

Class variables can be accessed anywhere within that class whereas an instance variable can only be accessed within the particular object of the class.

As class variables are common to all objects of a class, changes made to these variables through one object will reflect in another. As each object will have its own copy of instance variables, changes made to these variables through one object will not reflect in another object.

Class variables can be accessed using either class name or object reference. Instance variables can  be accessed only through an object reference

8 Explain inheritance in Python with an example.

Inheritance is a feature by which one class can gain all the attributes and methods of another class. This facilitates code reusability and a program one written can be reused by inheriting the parent class attributes without having to rewrite them every time. The class from which we are inheriting is called super-class and the class that is inherited is called a sub-class / derived class.

Single Inheritance – where a derived class acquires the members of a single superclass.

multi-level inheritance – a derived class d1 is inherited from base class base1, and d2 is inherited from base2.

hierarchical inheritance – from one base class you can inherit any number of child classes

multiple inheritances – a derived class is inherited from more than one base class.

 9 Explain the difference between local and global namespaces.

Local namespaces are created within a function when that function is called. Global namespaces are created when the program starts.

  • When would you use a continue statement in a for loop?

When processing a particular item is complete, to move on to the next, without executing further processing in the block continue statement is used. The continue statement states, the current item is done processing, move on to the next item.

  • When would you use a break statement in a for loop?

The break statement states that the function of the loop is over and to move on to the next block of code. For example, when the item being searched is found, there is no need to keep looping. The break statement comes into play here and the loop terminates and the execution moves on to the next section of the code.