python interview questions
Tech Interview

Python Interview Questions


These are the question probably asked in Python interview. Hope these python interview questions and answers help you to crack the interview in a successful way.

1. What is Python?

Python language is used in scripting and also it is a dynamic, interpreted programming language. It allows the programmer to express concepts in fewer lines of code than possible in languages such as Java or C++.

2. List the features of Python?

  • Python provides very high-level dynamic data types
  • Python supports automatic garbage collection.
  • Python can be easily integrated with C, C++, Java, ActiveX, COM, and CORBA.
  • Python supports functional and structured programming methods as well as OOP.
  • Python can be compiled to byte-code for building large applications.

3. Explain Python dictionaries?

It is a kind of hash table type. They consist of key-value pairs and a dictionary key can be of any Python type but usually strings or numbers.

4. How to create a dictionary in Python?

The dictionary is enclosed by {} -curly braces and Square brackets are used to assign and access the values.

READ  Hadoop Interview Questions

5. How to convert string to float in Python?

To convert string to float in a python float is used before the string.

Ex: float (x) – X will be the string which will be converted into a floating point variable.

6. How will you reverse the list in Python?

To Reverse object of list in place list. reverses () statement is used.

7. What are the rules for global and local variable in python?

If a variable is assigned to a new value inside the function, then it is local and if a variable is defined outside a function then it is globally implicit.

8. What is a module in Python?

The module is simply a runnable code in python. It is a Python object with names, attributes that can be used for the purpose of bind and reference. The module can define variables, functions and classes.

9. What is scope in Python?

Scope is a region in Python program where it could be used without any qualification. i.e when the unqualified referenced with a name, then it can be looked out in the namespace to find the object.

10. What are Tuple in Python?

Tuples are enclosed within the parentheses. It is another sequence of data type  that is  similar to the list. The values of the tuples are separated by commas.

11. What is lambda in Python?

It is an anonymous function often used as an inline function. General form of lambda is

12. What is a package in Python?

A packages in Python can have sub folders and modules. The package is imported by using import package Statement.

READ  SSAS Interview Questions

Ex: import folder2.subfolder3.module2

13. Given the  subclass of dictionary:

Will the code below work? Explain why or why not?


Yes, it works. Because whenever the key is missing the dictionary instance, will be automatically be instantiated with a list.

14. How to perform unit testing in Python?

A unit testing framework called unittest is provided by Python. A unittest module in Python supports automation testing, shutdown code for tests and sharing of setup, independence of the tests from the reporting framework. and aggregation of tests into collections.

15.How to remove the last object from a list?

The below statement is used to remove and return the last object from the list

python interview questions

16. What is the purpose of continue statement in Python?

It causes the loop to skip the remainder of its body code and immediately retest its condition prior to reiterate.

17. Explain pass statement in Python?

It is used when a statement is required syntactically but you do not want any command or code to execute.

18. What is in Python? is used to import  a module in a directory which is called as package import. Usually is an empty py file.

19. Explain Iterators in Python?

Several Iterators objects are defined in Python to support iteration over general and specific sequence types, dictionaries.

20. What does monkey patching mean in Python?

The term Monkey-patching refers only to dynamic modifications of a class or a module at run time. In other words, it refers to changing code sneakily at runtime.

READ  ASP.NET Interview Questions

21. List the functional approach that Python is taking.

  • map
  • filter
  • reduce
  • lambda
  • list comprehension

22. What is meant by immutable type objects?

Immutable objects are defined as the objects whose content cannot be changed after the creation.

  • Tuple
  • Set
  • Float
  • Frozen
  • Str
  • Int

23. What is the syntax of the map?

The syntax of map in Python is given as

24. List the mutable objects in Python?

Mutable object types can be changed after their creation.

  • List
  • Dict
  • Set
  • Byte array

25. Give the difference between del () and remove () methods of list?

The del () statement is used when you want to remove a exactly known list element and if the list element is unknown then the remove () statement will be used.