SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
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 in Python?
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 the function.
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.
Pickleis 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()
3 if 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

PPTX
Python Interview questions 2020
PPTX
Python
PDF
Top 20 Python Interview Questions And Answers 2023.pdf
PDF
K-Map, Logic Gates.pdf .
PPTX
Python - Numpy/Pandas/Matplot Machine Learning Libraries
PDF
Python Basics | Python Tutorial | Edureka
PPTX
Python-00 | Introduction and installing
PDF
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Interview questions 2020
Python
Top 20 Python Interview Questions And Answers 2023.pdf
K-Map, Logic Gates.pdf .
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python Basics | Python Tutorial | Edureka
Python-00 | Introduction and installing
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka

What's hot (20)

PDF
UGC NET Computer Science & Application book.pdf [Sample]
PPTX
Python Tutorial Part 1
PPTX
Functions in python slide share
PPT
Basic concept of OOP's
PPTX
Python pandas Library
DOCX
Automate the boring stuff with python
PPT
Introduction to Python
PPTX
12. Heaps - Data Structures using C++ by Varsha Patil
PPTX
Python interview questions and answers
PDF
Lesson 02 python keywords and identifiers
PDF
Pandas
PPTX
Data Structures in Python
PPTX
Formatted Console I/O Operations in C++
PPT
PYTHON - TKINTER - GUI - PART 1.ppt
PDF
Data visualization in Python
PPTX
Array Of Pointers
PPTX
control statements in python.pptx
PPTX
Basics of Object Oriented Programming in Python
PDF
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
PPTX
UGC NET Computer Science & Application book.pdf [Sample]
Python Tutorial Part 1
Functions in python slide share
Basic concept of OOP's
Python pandas Library
Automate the boring stuff with python
Introduction to Python
12. Heaps - Data Structures using C++ by Varsha Patil
Python interview questions and answers
Lesson 02 python keywords and identifiers
Pandas
Data Structures in Python
Formatted Console I/O Operations in C++
PYTHON - TKINTER - GUI - PART 1.ppt
Data visualization in Python
Array Of Pointers
control statements in python.pptx
Basics of Object Oriented Programming in Python
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Ad

Viewers also liked (13)

PPTX
CMP 2-13-16
PPTX
BET TRADERS WIN
PDF
CompTIA Network+ N10-006
PDF
DALICC (Data Licenses Clearance Centre)
PPTX
Deployment and distribution- iOS
PPTX
Literacy and numeracy
PDF
Jude Cosgrove - Early child health and cognitive outcomes: secondary analysi...
PPTX
Numeracy Information Evening KS1
PDF
Agile ncr agile coaching-v1
PPTX
CONSTRUCT YOUR DREAM HOME
PPTX
ECM Pre-Numeracy for Kindergarten
PPT
Literacy & Numeracy Week 2013 Reading With Our Buddies
DOCX
01 июля 2016 года на базе мбдоу
CMP 2-13-16
BET TRADERS WIN
CompTIA Network+ N10-006
DALICC (Data Licenses Clearance Centre)
Deployment and distribution- iOS
Literacy and numeracy
Jude Cosgrove - Early child health and cognitive outcomes: secondary analysi...
Numeracy Information Evening KS1
Agile ncr agile coaching-v1
CONSTRUCT YOUR DREAM HOME
ECM Pre-Numeracy for Kindergarten
Literacy & Numeracy Week 2013 Reading With Our Buddies
01 июля 2016 года на базе мбдоу
Ad

Similar to Python interview questions (20)

PDF
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
PDF
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
PDF
Python Course In Chandigarh
DOCX
Python Interview Questions For Experienced
DOCX
Python interview questions and answers
PDF
Python interview questions and answers
PPTX
Pyhton problem solving introduction and examples
PDF
Python_Unit_1.pdf
PPTX
Introduction to Python for Data Science and Machine Learning
PDF
Zero to Hero - Introduction to Python3
PPTX
Python (Data Analysis) cleaning and visualize
PPTX
Python intro
PDF
Python Viva Interview Questions PDF By ScholarHat
PDF
PPTX
lakshya's ppt python for final final.pptx
PDF
Python (3).pdf
DOCX
Python Course.docx
PPTX
Python presentation of Government Engineering College Aurangabad, Bihar
PPTX
Intro to python
PDF
Top Most Python Interview Questions.pdf
Top 80 Interview Questions on Python for Data Science | Tutort - Best Data Sc...
🐍⚡ “Python Panache: Code Like a Pro, Not a Programmer!”
Python Course In Chandigarh
Python Interview Questions For Experienced
Python interview questions and answers
Python interview questions and answers
Pyhton problem solving introduction and examples
Python_Unit_1.pdf
Introduction to Python for Data Science and Machine Learning
Zero to Hero - Introduction to Python3
Python (Data Analysis) cleaning and visualize
Python intro
Python Viva Interview Questions PDF By ScholarHat
lakshya's ppt python for final final.pptx
Python (3).pdf
Python Course.docx
Python presentation of Government Engineering College Aurangabad, Bihar
Intro to python
Top Most Python Interview Questions.pdf

More from Pragati Singh (20)

PDF
ISACA Membership-certificate-2034890 | ISACA
PDF
Leading AI driven Business Transformation.pdf
PDF
PMI Prompt Engineering | Gen AI Program Management
PDF
Shaping the Future of Project Management with AI.pdf
PDF
Nessus Scanner: Network Scanning from Beginner to Advanced!
PDF
Tenable Certified Sales Associate - CS.pdf
PDF
Analyzing risk (pmbok® guide sixth edition)
PDF
Pragati Singh | Sap Badge
PDF
Ios record of achievement
PDF
Ios2 confirmation ofparticipation
PDF
Certificate of completion android studio essential training 2016
PDF
Certificate of completion android development essential training create your ...
PDF
Certificate of completion android development essential training design a use...
PDF
Certificate of completion android development essential training support mult...
PDF
Certificate of completion android development essential training manage navig...
PDF
Certificate of completion android development essential training local data s...
PDF
Certificate of completion android development essential training distributing...
PDF
Certificate of completion android app development communicating with the user
PDF
Certificate of completion building flexible android apps with the fragments api
PDF
Certificate of completion android app development design patterns for mobile ...
ISACA Membership-certificate-2034890 | ISACA
Leading AI driven Business Transformation.pdf
PMI Prompt Engineering | Gen AI Program Management
Shaping the Future of Project Management with AI.pdf
Nessus Scanner: Network Scanning from Beginner to Advanced!
Tenable Certified Sales Associate - CS.pdf
Analyzing risk (pmbok® guide sixth edition)
Pragati Singh | Sap Badge
Ios record of achievement
Ios2 confirmation ofparticipation
Certificate of completion android studio essential training 2016
Certificate of completion android development essential training create your ...
Certificate of completion android development essential training design a use...
Certificate of completion android development essential training support mult...
Certificate of completion android development essential training manage navig...
Certificate of completion android development essential training local data s...
Certificate of completion android development essential training distributing...
Certificate of completion android app development communicating with the user
Certificate of completion building flexible android apps with the fragments api
Certificate of completion android app development design patterns for mobile ...

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Trump Administration's workforce development strategy
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
GDM (1) (1).pptx small presentation for students
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial diseases, their pathogenesis and prophylaxis
Weekly quiz Compilation Jan -July 25.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chinmaya Tiranga quiz Grand Finale.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Trump Administration's workforce development strategy
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
O5-L3 Freight Transport Ops (International) V1.pdf

Python interview questions

  • 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 in Python? 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 the function. 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. Pickleis 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() 3 if 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)