logo
Product
Product Tour
Aptitude Tests Coding Tests Psychometric Tests Personality Tests
Campus Hiring Features Proctoring Enterprise
Test Library Questions Pricing
Resources
Blog Case studies Books Tools
About us
Login
Log In

Search test library by skills or roles
⌘ K
logo
Assessment Platform Aptitude Tests Coding Tests Psychometric Tests Personality Tests

TRY FOR FREE

Python Interview Questions
  1. What are Literals in Python?
  2. What is PYTHONPATH?
  3. What is a lambda function?
  4. What is self in Python?
  5. What is the difference between range & xrange.
  6. Explain pickling and unpickling in Python.
  7. What is a dictionary in Python?
  8. Explain Multithreading in Python.
  9. What is Inheritance in Python?
  10. What is Scope in Python?
  11. What is pass in Python?
  12. Explain slicing in Python.
  13. What is Scope Resolution?
  14. Explain decorators.
  15. What is the use of help() and dir() functions?
  16. What is Polymorphism?
  17. Explain split() and join() in Python.
  18. What is encapsulation?
  19. What are access modifiers?
  20. Why is finalize used?
  21. What is type conversion?
  22. What are Python packages?
  23. What are python iterators?
  24. What is swapcase() function?
  25. What is docstring?
  26. What is monkey patching?
  27. What are lists and tuples?


Interview Questions

Python Interview Questions and Answers (2023)

In this post, we put together the top Python interview questions and answers for beginner, intermediate and experienced candidates. These most important questions are categorized for quick browsing before the interview or to act as a detailed guide on different topics in Python interviewers look for.

Python Online Test

Python Interview Questions

What are Literals in Python?

View answer

Hide answer

A literal is a succinct and easily visible way to write a value. Literals represent the possible choices in primitive types for that language. Some of the choices of types of literals are often integers, floating point, Booleans and character strings.

What is PYTHONPATH?

View answer

Hide answer

PYTHONPATH is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.

What is a lambda function?

View answer

Hide answer

In Python, a lambda function is a single-line function declared with no name, which can have any number of arguments, but it can only have one expression. Such a function is capable of behaving similarly to a regular function declared using the Python's def keyword.

What is self in Python?

View answer

Hide answer

Self is an instance or an object of a class. In Python, this is explicitly included as the first parameter. However, this is not the case in Java where it’s optional. It helps to differentiate between the methods and attributes of a class with local variables.

The self variable in the init method refers to the newly created object while in other methods, it refers to the object whose method was called.

What is the difference between range & xrange.

View answer

Hide answer

Explain pickling and unpickling in Python.

View answer

Hide answer

Pickling is the name of the serialization process in Python. Any object in Python can be serialized into a byte stream and dumped as a file in the memory. The process of pickling is compact but pickle objects can be compressed further. Moreover, pickle keeps track of the objects it has serialized and the serialization is portable across versions.

Unpickling is the inverse of pickling. It deserializes the byte stream to recreate the objects stored in the file and loads the object to memory.

What is a dictionary in Python?

View answer

Hide answer

Dictionaries are used to store data values in key:value pairs.

A dictionary is a collection which is ordered, changeable and does not allow duplicates.

Explain Multithreading in Python.

View answer

Hide answer

Multithreading refers to concurrently executing multiple threads by rapidly switching the control of the CPU between threads (called context switching). The Python Global Interpreter Lock limits one thread to run at a time even if the machine contains multiple processors.​

What is Inheritance in Python?

View answer

Hide answer

Inheritance allows us to define a class that inherits all the methods and properties from another class. Parent class is the class being inherited from, also called base class. Child class is the class that inherits from another class, also called derived class.

What is Scope in Python?

View answer

Hide answer

The scope defines the accessibility of the python object. To access the particular variable in the code, the scope must be defined as it cannot be accessed from anywhere in the program. The particular coding region where variables are visible is known as scope.

What is pass in Python?

View answer

Hide answer

The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.

Explain slicing in Python.

View answer

Hide answer

Slicing is a technique that allows us to retrieve only a part of a list, tuple, or string. For this, we use the slicing operator [].

What is Scope Resolution?

View answer

Hide answer

Scope resolution is required when a variable is used to determine where should its value be come from. Scope resolution in Python follows the LEGB rule. L, Local — Names assigned in any way within a function (or lambda), and not declared global in that function.

Explain decorators.

View answer

Hide answer

A decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.

What is the use of help() and dir() functions?

View answer

Hide answer

Help() and dir(), are the two functions that are reachable from the python interpreter. Both functions are utilized for observing the combine dump of build-in-function. These created functions in python are truly helpful for the efficient observation of the built-in system.

What is Polymorphism?

View answer

Hide answer

Polymorphism in python defines methods in the child class that have the same name as the methods in the parent class. In inheritance, the child class inherits the methods from the parent class. Also, it is possible to modify a method in a child class that it has inherited from the parent class.

Explain split() and join() in Python.

View answer

Hide answer

You can use split() function to split a string based on a delimiter to a list of strings. You can use join() function to join a list of strings based on a delimiter to give a single string.

What is encapsulation?

View answer

Hide answer

Encapsulation is a fundamental concept in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit. This puts restrictions on accessing variables and methods directly and can prevent the accidental modification of data. To prevent accidental change, an object’s variable can only be changed by an object’s method. Those types of variables are known as private variables.

What are access modifiers?

View answer

Hide answer

There are three types of access modifiers in Python: public, private, and protected.

  • Variables with the public access modifiers can be accessed anywhere inside or outside the class
  • Private variables can only be accessed inside the class
  • Protected variables can be accessed within the same package

Why is finalize used?

View answer

Hide answer

finalize is a direct way to register a cleanup function to be called when an object is garbage collected. This is simpler to use than setting up a callback function on a raw weak reference, since the module automatically ensures that the finalizer remains alive until the object is collected.

What is type conversion?

View answer

Hide answer

Python defines type conversion functions like int(), float(), str() to directly convert one data type into another. This type of conversion is also called typecasting because the user casts (change) the data type of the objects. This function converts any data type into integer.

What are Python packages?

View answer

Hide answer

A python package is a collection of modules. Modules that are related to each other are mainly put in the same package. When a module from an external package is required in a program, that package can be imported and its modules can be put to use.

What are python iterators?

View answer

Hide answer

Iterator in python is an object that is used to iterate over iterable objects like lists, tuples, dicts, and sets. The iterator object is initialized using the iter() method. It uses the next() method for iteration.

What is swapcase() function?

View answer

Hide answer

The swapcase() method returns a string where all the upper case letters are lower case and vice versa.

What is docstring?

View answer

Hide answer

Python documentation string (docstring) is a string literal used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (doc) for any of the Python objects and also with the built-in help() function. An object's docstring is defined by including a string constant as the first statement in the object's definition.

What is monkey patching?

View answer

Hide answer

In Python, the term monkey patch only refers to dynamic modifications of a class or module at runtime, which means monkey patch is a piece of Python code that extends or modifies other code at runtime.

What are lists and tuples?

View answer

Hide answer

A list is a collection of arbitrary objects, somewhat akin to an array in many other programming languages but more flexible. Lists are defined in Python by enclosing a comma-separated sequence of objects in square brackets ([]).

Tuples are identical to lists in all respects, except for the following properties:

  • Tuples are defined by enclosing the elements in parentheses (()) instead of square brackets ([])
  • Tuples are immutable
Other Interview Questions

ReactJS

Business Analyst

Android

Javascript

Power BI Django .NET Core
Java 8 R PostgreSQL
Spring Boot Drupal TestNG
Check Other Interview Questions
Join 1200+ companies in 75+ countries.
Try the most candidate friendly skills assessment tool today.
GET STARTED FOR FREE
40 min tests.
No trick questions.
Accurate shortlisting.

[email protected]

Product
  • Product Tour
  • Pricing
  • Features
  • Integrations
Usecases
  • Aptitude Tests
  • Coding Tests
  • Psychometric Tests
  • Personality Tests
Helpful Content
  • 52 pre-employment tools compared
  • Compare Adaface
  • Compare Codility vs Adaface
  • Compare HackerRank vs Adaface
  • Compare Mettl vs Adaface
BOOKS & TOOLS
  • Guide to pre-employment tests
  • Check out all tools
Company
  • About Us
  • Join Us
  • Blog
Locations
  • Singapore (HQ)

    32 Carpenter Street, Singapore 059911

    Contact: +65 9447 0488

  • India

    WeWork Prestige Atlanta, 80 Feet Main Road, Koramangala 1A Block, Bengaluru, Karnataka, 560034

    Contact: +91 6305713227

© 2022 Adaface Pte. Ltd.
Terms Privacy Trust Guide

🌎 Pick your language

English Norsk Dansk Deutsche Nederlands Svenska Français Español Chinese (简体中文) Italiano Japanese (日本語) Polskie Português Russian (русский)
Search 500+ tests by skill or role name