SlideShare a Scribd company logo
Python Interview Questions
A list of top frequently asked Python interview questions
and answers are given below.
1) What is Python?
Python is a high level object-oriented programming language
with objects, modules, threads, exceptions and automatic
memory management. It is a simple yet powerful
programming language. It can run equally on different
platforms such as Windows, Linux, UNIX, Macintosh etc. Thus,
Python is a portable language.
2) What are the advantages of Python?
Following are the main advantages of using Python.
◦ Free and open source
◦ Portable
◦ Extensible
◦ Object oriented
◦ Built-in data structure
3)What is PEP 8?
PEP 8 is a coding convention which specifies a set of
guidelines, about how to write your Python code more
readable.
4)What is used to create Unicode string in
Python?
You should use "Unicode" before the string. For example:
Unicode (text).
5) Explain how Python is interpreted?
Python is an interpreted language. The Python language
program runs directly from the source code. It converts the
source code into an intermediate language, which is again
translated into machine language that has to be executed.
6) How memory is managed in Python?
Memory is managed in Python in following way:
◦ Memory is managed in Python by private heap space. All
Python objects and data structures are located in a
private heap. The programmer does not have an access
to this private heap and interpreter takes care of this
Python private heap.
◦ Python memory manager is responsible for allocating Python
heap space for Python objects.
◦ Python also have an inbuilt garbage collector, which recycle
all the unused memory and frees the memory and makes
it available to the heap space.
7) What is Python decorator?
A Python decorator is a specific change made within Python
syntax to alter functions easily.
8)What are the rules for local and global
variable inPython?
In Python, variables that are only referenced inside a function
are called implicitly global. If a variable is assigned a new
value anywhere within the function's body, it's assumed to be
a local. If a variable is ever assigned a new value inside the
function, the variable is implicitly local, and you need to
explicitly declare it as 'global'.
9) What is namespace in Python?
In Python, every name has a place where it lives and can be
hooked for. This is known as namespace. It is like a box where
a variable name is mapped to the object placed. Whenever the
variable is searched out, this box will be searched, to get
corresponding object.
10) What are iterators in Python?
In Python, iterators are used to iterate a group of elements,
containers like list.
11) What is generator in Python?
In Python, generator is a way that specifies how to implement
iterators. It is a normal function except that it yields
expression in thefunction.
12) What is slicing in Python?
Slicing is a mechanism used to select a range of items from
sequence type like list, tuple, string etc.
13) What is dictionary in Python?
The built-in datatypes in Python is called dictionary. It defines
one-to-one relationship between keys and values. Dictionaries
contain pair of keys and their corresponding values.
Dictionaries are indexed by keys.
Let's take an example
The following example contains some keys ? Country Hero &
Cartoon. Their corresponding values are India, Modi and Rahul
respectively.
1 >>> dict = {'Country': 'India', 'Hero': 'Modi', 'Cartoon': 'Rah
ul'}
2 >>>print dict[Country]
3 India
4 >>>print dict[Hero]
5 Modi
6 >>>print dict[Cartoon]
7 Rahul
14) What is Pass in Python?
Pass specifies a Python statement without operations. It is a
place holder in a compound statement, where there should be
a blank left and nothing has to be written there.
15) Explain docstring in Python?
A Python documentation string is called docstring. It is used
for documenting Python functions, modules and classes.
16) What is negative index in Python?
Python sequences are indexed in positive and negative
numbers. For example: 0 is the first positive index, 1 is the
second positive index and so on. For negative indexes -1 is the
last negative index, -2 is the second last negative index and so
on.
17)What is pickling and unpickling in
Python?
Pickling is a process in which a pickle module accepts any
Python object, converts it into a string representation and
dumps it into a file by using dump() function.
Unpickling is a process of retrieving original Python object
from the stored string representation for use.
Pickle is a standard modulewhich serializes and de-serializes
a Python objectstructure.
18) How can you make forms in Python?
You have to import cgi module to access form fields using
FieldStorage class.
Attributes of class FieldStorage for form:
form.name: The name of the field, if specified.
form.filename: If an FTP transaction, the client-side
filename.
form.value: The value of the field as a string.
form.file: file object from which data can be read.
form.type: The content type, if applicable.
form.type_options: The options of the 'content-type' line of
the HTTP request, returned as a dictionary.
form.disposition: The field 'content-disposition'; None, if
unspecified.
form.disposition_options: The options for 'content-
disposition'.
form.headers: All of the HTTP headers returned as a
dictionary.
Example
1 import cgi
2 form = cgi.FieldStorage()
3if not (form.has_key("name") and form.has_key("age")):
4 print "<H1>Name & Age not Entered</H1>"
5 print "Fill the Name & Age accurately."
6 return
7 print "<p>name:", form["name"].value
8 print "<p>Age:", form["age"].value
19)What are the differences between
Python 2.x and Python 3.x?
Python 2.x is an older version of Python. It is a legacy now.
Python 3.x is newer. It is the present and future of this
language.
The most visible difference between them is in print
statement. In Python 2 it is print ?Hello? and in Python 3, it is
print (?Hello?).
20)How can you organize your code to
make it easier to change the base class?
You have to define an alias for the base class, assign the real
base class to it before your class definition, and use the alias
throughout your class. you can also use this method if you
want to decide dynamically (e.g. depending on availability of
resources) which base class to use.
Example
1 BaseAlias = <real base class>
2 class Derived(BaseAlias):
3 def meth(self):
4 BaseAlias.meth(self)

More Related Content

DOCX
Python interview questions
PDF
What is Python Lambda Function? Python Tutorial | Edureka
PPTX
Python
PDF
Functional Programming in Python
PPTX
Python Lambda Function
PDF
Python Programming Language | Python Classes | Python Tutorial | Python Train...
PDF
Function in Python
PPTX
Python
Python interview questions
What is Python Lambda Function? Python Tutorial | Edureka
Python
Functional Programming in Python
Python Lambda Function
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Function in Python
Python

What's hot (20)

PPTX
Dynamic memory allocation in c
PPTX
Python 3 Programming Language
PPTX
UNIT 10. Files and file handling in C
PPTX
Typedef
PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PPT
[ppt]
PPTX
Simple if else statement,nesting of if else statement &amp; else if ladder
PPTX
Natural Language processing Parts of speech tagging, its classes, and how to ...
PPTX
Data types in C language
PDF
Data Structures for Statistical Computing in Python
PDF
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
PDF
Python Basics
PDF
Python lambda functions with filter, map & reduce function
PPTX
FHIR API for .Net programmers by Mirjam Baltus
PPTX
Parameter passing to_functions_in_c
PPTX
Lecture 1: Semantic Analysis in Language Technology
DOCX
Structure and Typedef
PPT
ConsTRUCTION AND DESTRUCTION
PPTX
Data Structures in Python
Dynamic memory allocation in c
Python 3 Programming Language
UNIT 10. Files and file handling in C
Typedef
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
[ppt]
Simple if else statement,nesting of if else statement &amp; else if ladder
Natural Language processing Parts of speech tagging, its classes, and how to ...
Data types in C language
Data Structures for Statistical Computing in Python
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Basics
Python lambda functions with filter, map & reduce function
FHIR API for .Net programmers by Mirjam Baltus
Parameter passing to_functions_in_c
Lecture 1: Semantic Analysis in Language Technology
Structure and Typedef
ConsTRUCTION AND DESTRUCTION
Data Structures in Python
Ad

Similar to Python Interview questions 2020 (20)

PDF
Python_Interview_Questions.pdf
PPTX
Introduction to Programming.pptx ok ok ok
PDF
Python Viva Interview Questions PDF By ScholarHat
PDF
Python Interview Preparation questons...
DOCX
Python interview questions and answers
PPTX
Python_Buildin_Data_types_Lecture_8.pptx
DOCX
Python Interview Questions For Experienced
PPTX
Python unit 2 is added. Has python related programming content
PDF
Top Most Python Interview Questions.pdf
PDF
Python interview questions and answers
PDF
problem solving and python programming UNIT 2.pdf
PDF
Problem Solving and Python Programming UNIT 2.pdf
PDF
interviewbit.pdf
PDF
Top 100 Python Interview Questions And Answers
PDF
web programming UNIT VIII python by Bhavsingh Maloth
PDF
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
PPTX
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
PDF
Tutorial on-python-programming
PPTX
Python Tutorial for Beginner
PPT
Unit 2 python
Python_Interview_Questions.pdf
Introduction to Programming.pptx ok ok ok
Python Viva Interview Questions PDF By ScholarHat
Python Interview Preparation questons...
Python interview questions and answers
Python_Buildin_Data_types_Lecture_8.pptx
Python Interview Questions For Experienced
Python unit 2 is added. Has python related programming content
Top Most Python Interview Questions.pdf
Python interview questions and answers
problem solving and python programming UNIT 2.pdf
Problem Solving and Python Programming UNIT 2.pdf
interviewbit.pdf
Top 100 Python Interview Questions And Answers
web programming UNIT VIII python by Bhavsingh Maloth
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
Tutorial on-python-programming
Python Tutorial for Beginner
Unit 2 python
Ad

Recently uploaded (20)

PPTX
Transform Your Business with a Software ERP System
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
top salesforce developer skills in 2025.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
assetexplorer- product-overview - presentation
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Cost to Outsource Software Development in 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
medical staffing services at VALiNTRY
PDF
Digital Strategies for Manufacturing Companies
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Transform Your Business with a Software ERP System
Operating system designcfffgfgggggggvggggggggg
top salesforce developer skills in 2025.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
CHAPTER 2 - PM Management and IT Context
Why Generative AI is the Future of Content, Code & Creativity?
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administration Chapter 2
Design an Analysis of Algorithms II-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Odoo Companies in India – Driving Business Transformation.pdf
assetexplorer- product-overview - presentation
wealthsignaloriginal-com-DS-text-... (1).pdf
Cost to Outsource Software Development in 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
medical staffing services at VALiNTRY
Digital Strategies for Manufacturing Companies
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Python Interview questions 2020

  • 1. Python Interview Questions A list of top frequently asked Python interview questions and answers are given below. 1) What is Python? Python is a high level object-oriented programming language with objects, modules, threads, exceptions and automatic memory management. It is a simple yet powerful programming language. It can run equally on different platforms such as Windows, Linux, UNIX, Macintosh etc. Thus, Python is a portable language. 2) What are the advantages of Python? Following are the main advantages of using Python. ◦ Free and open source ◦ Portable ◦ Extensible ◦ Object oriented ◦ Built-in data structure 3)What is PEP 8? PEP 8 is a coding convention which specifies a set of guidelines, about how to write your Python code more readable. 4)What is used to create Unicode string in Python? You should use "Unicode" before the string. For example: Unicode (text). 5) Explain how Python is interpreted? Python is an interpreted language. The Python language program runs directly from the source code. It converts the source code into an intermediate language, which is again translated into machine language that has to be executed. 6) How memory is managed in Python? Memory is managed in Python in following way: ◦ Memory is managed in Python by private heap space. All
  • 2. Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap. ◦ Python memory manager is responsible for allocating Python heap space for Python objects. ◦ Python also have an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space. 7) What is Python decorator? A Python decorator is a specific change made within Python syntax to alter functions easily. 8)What are the rules for local and global variable inPython? In Python, variables that are only referenced inside a function are called implicitly global. If a variable is assigned a new value anywhere within the function's body, it's assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as 'global'. 9) What is namespace in Python? In Python, every name has a place where it lives and can be hooked for. This is known as namespace. It is like a box where a variable name is mapped to the object placed. Whenever the variable is searched out, this box will be searched, to get corresponding object. 10) What are iterators in Python? In Python, iterators are used to iterate a group of elements, containers like list. 11) What is generator in Python? In Python, generator is a way that specifies how to implement iterators. It is a normal function except that it yields expression in thefunction. 12) What is slicing in Python?
  • 3. Slicing is a mechanism used to select a range of items from sequence type like list, tuple, string etc. 13) What is dictionary in Python? The built-in datatypes in Python is called dictionary. It defines one-to-one relationship between keys and values. Dictionaries contain pair of keys and their corresponding values. Dictionaries are indexed by keys. Let's take an example The following example contains some keys ? Country Hero & Cartoon. Their corresponding values are India, Modi and Rahul respectively. 1 >>> dict = {'Country': 'India', 'Hero': 'Modi', 'Cartoon': 'Rah ul'} 2 >>>print dict[Country] 3 India 4 >>>print dict[Hero] 5 Modi 6 >>>print dict[Cartoon] 7 Rahul 14) What is Pass in Python? Pass specifies a Python statement without operations. It is a place holder in a compound statement, where there should be a blank left and nothing has to be written there. 15) Explain docstring in Python? A Python documentation string is called docstring. It is used for documenting Python functions, modules and classes. 16) What is negative index in Python? Python sequences are indexed in positive and negative numbers. For example: 0 is the first positive index, 1 is the second positive index and so on. For negative indexes -1 is the last negative index, -2 is the second last negative index and so on. 17)What is pickling and unpickling in Python? Pickling is a process in which a pickle module accepts any
  • 4. Python object, converts it into a string representation and dumps it into a file by using dump() function. Unpickling is a process of retrieving original Python object from the stored string representation for use. Pickle is a standard modulewhich serializes and de-serializes a Python objectstructure. 18) How can you make forms in Python? You have to import cgi module to access form fields using FieldStorage class. Attributes of class FieldStorage for form: form.name: The name of the field, if specified. form.filename: If an FTP transaction, the client-side filename. form.value: The value of the field as a string. form.file: file object from which data can be read. form.type: The content type, if applicable. form.type_options: The options of the 'content-type' line of the HTTP request, returned as a dictionary. form.disposition: The field 'content-disposition'; None, if unspecified. form.disposition_options: The options for 'content- disposition'. form.headers: All of the HTTP headers returned as a dictionary. Example 1 import cgi 2 form = cgi.FieldStorage() 3if not (form.has_key("name") and form.has_key("age")): 4 print "<H1>Name & Age not Entered</H1>" 5 print "Fill the Name & Age accurately." 6 return 7 print "<p>name:", form["name"].value 8 print "<p>Age:", form["age"].value 19)What are the differences between Python 2.x and Python 3.x? Python 2.x is an older version of Python. It is a legacy now. Python 3.x is newer. It is the present and future of this language. The most visible difference between them is in print statement. In Python 2 it is print ?Hello? and in Python 3, it is
  • 5. print (?Hello?). 20)How can you organize your code to make it easier to change the base class? You have to define an alias for the base class, assign the real base class to it before your class definition, and use the alias throughout your class. you can also use this method if you want to decide dynamically (e.g. depending on availability of resources) which base class to use. Example 1 BaseAlias = <real base class> 2 class Derived(BaseAlias): 3 def meth(self): 4 BaseAlias.meth(self)