Python Interview Questions 1

Python Interview Questions 1

Python-Interview-Questions-AnswersWhat is Script?

  • A program that serves the application (Standalone or Web) that was developed using another programming language.
  • Script is a set of instructions that will be interpreted.
  • Script carried out by another program rather than by the computer processor.

Why Python programming language?

  • Every programming language has its scope. Different programming languages used for different types of application development.
  • Python script analyzes the data effectively using its pre-defined functionality than other programming codes.
  • Python can be used in web development, Gaming development, Embedded System applications and many more.

What is the difference between Script and Program?

  • A Program (Process) is a set of instructions.
  • A script is a sub program or sub process.

What is a Compiler?

  • A translator that converts the source code (high level instructions set) into either machine code or interpreter understandable code.

Can we modify a list?

Yes, List is mutable collection object. Hence we can modify the object by adding or removing the elements once it has been created.


Can we modify a tuple?

  • No, tuple is immutable object.
  • Immutable objects are constants hence we cannot modify once it has created.

Attend Free Demo of  Python Online Training


Can we modify a tuple element?

  • Tuple elements can be Mutable or Immutable.
  • If the element is Mutable like List, we can modify.
  • If the element is immutable like int, float , string and Tuple cannot be modified.

Can we store a List inside Tuple?

  • Yes allowed.
  • Tuple can able to store both Mutable and Immutable objects.
  • List is Mutable hence that cannot be stored as an element.

Differentiate Compilation and Interpretation?

  • Compiler translates the source code into machine code all at once only if all instructions are syntactically correct.
  • Interpreter translates the code line by line and generates the output for translated instruction instantly.

What is the return type of input() function?

  • Input() function reads the end user input in the program.
  • It returns the input values in String format.

 How can we process the input values in the application?

  • We can convert the String type elements into corresponding type using pre-defined data conversion methods such as int() , float() ….

What is the use of ‘pass’ keyword?

  • ‘pass’ keyword is used to define empty blocks, functions and classes.

Attend Free Demo of  Python Online Training


What is a break statement?

“Break” is used to terminate the flow of a loop.


Differentiate Break and Continue?

“Break” is used to terminate the loop completely where as “Continue” is used to end the current iteration and continue with remaining iterations execution.


Can we store a Tuple inside List?

  • List allows both Mutable and Immutable objects as elements.
  • Tuple is Immutable and it can be stored as an element.

Can we store a set inside another set?

No.

  • Set is Mutable.
  • Set elements must be immutable.

Can we store a Tuple as a key in a dictionary?

  • Yes allowed, a tuple is Immutable and Dictionary keys are Immutable.

Does python contain a char data type?

  • No, python supports only string type.
  • A character in python is a String of length 1.

Attend Free Demo of  Python Online Training


What is the use of chr() function in Python?

  • chr() function returns the corresponding symbol of specified integer value.
  • For example  chr(97) is ‘a’

How can we represent a String in python?

  • String is a one dimensional character array.
  • We can represent Strings either by using single quotes or double quotes.

Can we add String and integer directly using + operator?

  • No, we cannot concatenate String and Integer directly. We need to convert integer into string to merge.
  • string = string + str(int)

What is the use of str( ) function?

Converts specified input value(int or float..) into String type.

str(10) à “10”


Can we convert a character into integer using int() function?

  • No, int() function is used to convert the specified input(convertible integer) into int type.

For example,

int(“12”) à 12

int(34.56) à 34

int(“abc”) à Error :

 


Attend Free Demo of  Python Online Training


What is the use of ord( ) function?

  • ord( ) function is used to convert the specified symbol(A string of length 1) into integer.

 How to convert a string into float ?

  • float() function is pre-defined and it can be used to convert String to float(if the string contains convertible float value) else it raises exception.

What is a function?

  • Set of instructions having identity. A function takes input, process input and generates output.

Differentiate Function and Method?

  • Both are same.
  • We call it as a Function in Procedure oriented programming and Method in Object
  • Oriented programming.

What is the Keyword argument Function?

  • Calling the function by passing values along with argument names.
  • Argument names working like keys.
  • While using keys(argument identities), no need to follow the order of arguments to pass values.

What is the use of variable arguments Function?

  • Variable argument functions can able to collect different length of parameter values.
  • A pointer type variable collects all these values.

What is the Default argument function?

  • Assigning values directly to an argument in the function definition.
  • Passing parameter values to these arguments is optional.
  • We can replace these values if required.

Can we place a non default argument followed by default argument?

  • No, it is not possible to place default argument preceded by non default argument.

Attend Free Demo of  Python Online Training


What is class?

  • The complete representation of real world entity(object) is called class.
  • It is a blue print or model of object.
  • A collection of similar objects can be defined using class template.

What is object?

  • A real world entity with an identity, properties and functionality.
  • Identity is unique and it is used to access the object.
  • Properties represent information of Object.
  • Functionality describes capability of object.

Describe self reference variable?

  • The most recommended variable used to define object level methods.
  • It must be placed as first argument in the method definition.
  • It holds object address and it is used to invoke object level methods.

What is the need of encapsulation?

  • Protecting the object members(data and code) is the concept of encapsulation.
  • We can implement Encapsulation in object oriented programming using ‘class’.

What is inheritance?

  • Defining an object by extending(updating) the functionality of existing object.
  • It includes, accessing existing object functionality, adding new functionality and updating existing functionality if required.

Attend Free Demo of  Python Online Training


What is the advantage of inheritance?

  • The main advantage of inheritance is code re-usability.

How interpreters differ from the compiler ?

  • A compiler translates the source code all at once whereas Interpreter translates the code line by line.

Why python is interpreted programming language?

  • Python code need not be compiled.
  • Python interpreter is able to run the source code directly and generate output.

Describe the local variable?

  • Definition of a variable inside a block or function.
  • It can be accessed only within the block in which it has defined.

Is python an object-oriented programming language?

  • Python is fully object-oriented programming language. Every data element in python is an object. It doesn’t support primitive types

What is the global variable in Python?

  • Defining variable outside to all the functions referred to as Global variable.
  • The scope of the global variable is throughout the program.

What are the advantages of functions?

  • Code re-usability
  • Easy implementation of application

What is the use of a global keyword?

  • The keyword is used to create, access and process the global variables information from the function.

Attend Free Demo of  Python Online Training


Does python support data types?

  • Python is dynamic programming language.
  • It stores the information in the form of object.
  • It doesn’t store primitive data. Primitive data type size is fixed but not object size.
  • If we able to store the data of any size is called dynamic language.

What is method overriding?

  • Defining a method in the child class with the same name and same signature of parent class method.
  • Overriding can be implemented only in Parent-Child relation.

What is the need of method overriding?

  • The main advantage of method overriding (re-writing) is to update Parent object functionality in the child class if it is not sufficient to Child class.

Define abstraction?

  • Abstraction is the concept of hiding unnecessary details of object and showing essential features to communicate.

What is the object reference variable?

  • A user variable that holds the address of Object is called Object reference variable.

How to initialize the Parent object in the process of Child object creation?

  • By invoking the Parent class constructor(__init__) from the Child class constructor in Child object creation process.

Attend Free Demo of  Python Online Training


What is the use of super() method?

  • super() method is used to access Parent class functionality from Child class.
  • Super() method is used to access the any super class functionality by specifying its Child reference.

Does python support Hybrid inheritance?

  • Yes, python supports Hybrid inheritance. It is also called Diamond inheritance.

What is the difference between match() and search() functions in Regular expressions?

  • match() function is used to check whether the string starts with specified pattern or not.
  • search() function is used to find whether the string contains specified pattern or not.

Define polymorphism?

  • Defining an object(class) that shows different behavior(functionality) with the same identity.

What is method overloading technique?

  • Defining method more than once with the same name and different signature.
  • We can implement method overloading inside a class.

How can we achieve method overloading in python?

  • It is not possible to implement method overloading in python programming. Overloading is called compile time binding. Python is interpreted programming language.

Attend Free Demo of  Python Online Training


What is Constructor?

  • A special method invokes automatically in object creation process.

How to access the Overridden method of Parent class from Child?

  • Using super() method, we can access Parent class functionality from Child class area.

How to access Grandparent object level functionality from Child?

  • By invoking super(Parent, object_ref).

What is runtime polymorphism?

  • It is also called dynamic binding. It is method overriding technique.
  • Writing the method in the Child class with the same name and same signature with Parent class method.

What is ‘self’ ?

  • The most recommended variable to define object level methods and constructors.
  • ‘self’ holds object address hence it is also called ‘Reference variable’.

Can I access ‘self’ anywhere in the program?

  • ‘self’ is an argument of function or constructor
  • ‘arguments’ are working like local variables.
  • Local variables can be accessed only within the function.

What is Exception?

  • It is a run time error.
  • Exception either pre-defined class or user defined class.

Why handling exceptions?

  • The exception causes abnormal termination of Program execution.
  • The exception provides informal information to End-user.

How to handle exceptions in Python?

  • Using try-except blocks, we can handle exceptions in python.

What is a try ?

  • It is a keyword
  • It is a block of instructions.
  • Doubtful code that raises exceptions must be placed inside the try block in exception handling.

Attend Free Demo of  Python Online Training


Share this post