0% found this document useful (0 votes)
19 views

python_Viva_que_sw read

Uploaded by

Ayush Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

python_Viva_que_sw read

Uploaded by

Ayush Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

To view the live version of the

page,

© Copyright by Interviewbit
oC e

Python Interview Questions for Freshers


1. What is Python?
2. What are the benefits of using Python?
3. What is a dynamically typed language?
What is an Interpreted language?
FOS

What is PEP 8 and why is it important?


What is Scope in Python?
NS

What are lists and tuples? What is the key difference between the two?
What are the common built-in data types in Python?
SF

What is pass in Python?


eo

. What are modules and packages in Python?


11. What are global, protected and private attributes in Python?
12. What is self in Python?
13. Whatis init?

14. What is break, continue and pass in Python?


15. What are unit tests in Python?
16. What is docstring in Python?
17. What is slicing in Python?
18. Explain how can you make a Python Script executable on Unix?
19. What is the difference between Python Arrays and lists?

Page 1 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

Python Interview Questions for Experienced


20. Howis memory managed in Python?
21. What are Python namespaces? Why are they used?
22. What is Scope Resolution in Python?
23. What are decorators in Python?
24. What are Dict and List comprehensions?
25. What is lambda in Python? Why is it used?
26. How do you copy an object in Python?
27. What is the difference between xrange and range in Python?
28. What is pickling and unpickling?
29. What are generators in Python?
30. What is PYTHONPATH in Python?
31. What is the use of help() and dir() functions?
32. What is the difference between .py and .pyc files?
33. How Python is interpreted?
34. How are arguments passed by value or by reference in python?
35. What are iterators in Python?
36. Explain how to delete a file in Python?
37. Explain split() and join() functions in Python?
38. What does *args and *“*kwargs mean?
39. What are negative indexes and why are they used?

Page 2 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

Python OOPS Interview Questions


40. Howdo you create a class in Python?
41. How does inheritance work in python? Explain it with an example.
42. How do you access parent members in the child class?
43. Are access specifiers used in python?
44. lsit possible to call parent class without its instance creation?
45. Howisan empty class created in python?
46. Differentiate between new and override modifiers.
47. Whyis finalize used?
48. What is init method in python?
49. How will you check if a class is a child of another class?

Python Pandas Interview Questions


50. What do you know about pandas?
51. Define pandas dataframe.
52. How will you combine different pandas dataframes?
53. Can you create a series from the dictionary object in pandas?
54. Howwill you identify and deal with missing values in a dataframe?
55. What do you understand by reindexing in pandas?
56. Howto add new column to pandas dataframe?
57. How will you delete indices, rows and columns from a dataframe?

Page 3 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

Python Pandas Interview Questions


58. Can you get items of seriesA that are not available in another series B?
59. How will you get the items that are not common to both the given series A and
B?
60. While importing data from different sources, can the pandas library recognize
dates?

Numpy Interview Questions


61. What do you understand by NumPy?
62. How are NumPy. arrays advantageous over python lists?
63. What are the steps to create 1D, 2D and 3D arrays?
64. You are given a numpy array and a new column as inputs. How will you delete
the second column and replace the column with a new column value?
65. How will you efficiently load data from a text file?
66. How will you read CSV data into an array in NumPy?
67. How will you sort the array based on the Nth column?
68. How will you find the nearest value in a given numpy array?
69. How will you reverse the numpy array using one line of code?
70. How will you find the shape of any given NumPy array?

Python Libraries Interview Questions


‘1. Differentiate between a package and a module in python.
72. What are some of the most commonly used built-in modules in Python?
73. What are lambda functions?
14. How can you generate random numbers?

Page 4 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

Python Libraries Interview Questions


15. Can you easily check if all characters in the given string is alphanumeric?
76. What are the differences between pickling and unpickling?
ae Define GIL.
78. Define PYTHONPATH.

19. Define PIP.


80. Are there any tools for identifying bugs and performing static analysis in python?
81. Differentiate between deep and shallow copies.
82. What is main function.in python? How do you invoke it?

Python Programming Examples


83. Write python function which takes a variable number of arguments.
84. WAP (Write a program) which takes a sequence of numbers and check if all
numbers are unique.
85. Write a program for counting the number of every character of a given text file.
86. Write a program to check and return the pairs of a given array
A whose sum
value is equal to a target value N.
87. Write a Program to add two integers >0 without using the plus operator.
88. Write a Program to solve the given equation assuming that a,b,c,m,n,o are
constants:

89. Write a Program to match a string that has the letter ‘a’ followed by 4 to 8 'b’s.
90. Write a Program to convert date from yyyy-mm-dd format to dd-mm-yyyy
format.

91. Write a Program to combine two different dictionaries. While combining, if you
find the same keys, you can add the values of these same keys. Output the new
dictionary
92. How will you access the dataset of a publicly shared spreadsheet in CSV format
stored in Google Drive?

Page 5 © Copyright by Interviewbit


Let's get Started

Introduction to Python:

Python was developed by Guido van Rossum and was released first on February 20,
1991. It is one of the most widely-used and loved programming languages and is
interpreted in nature thereby providing flexibility of incorporating dynamic
semantics. It is also a free and open-source language with very simple and clean
syntax. This makes it developers easy to learn python. Python also supports object-
oriented programming and is most commonly used to perform general-purpose
programming. Due to its simplistic nature and the ability to achieve multiple
functionalities in fewer lines of code, python’s popularity is growing tremendously.
Python is also used in Machine Learning, Artificial Intelligence, Web Development,
Web Scraping, and various other domains due to its ability to support powerful
computations using powerful libraries. Due to this, there is a huge demand for
python developers in India and across the world. Companies are willing to offer
amazing perks.and benefits to these developers. In this article, we will see the most
commonly asked python interview questions and answers which will help you excel
and bag amazing job offers.
We have classified them into the following sections:

Python Interview Questions for Freshers


Python Interview Questions for Experienced
Python OOPS Interview Questions
Python Pandas Interview Questions
Numpy Interview Questions
Python Libraries Interview Questions
Python Programming Examples

Page 6 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

Python Interview Questions for Freshers


1. What is Python?
Python is a high-level, interpreted, general-purpose programming language. Being a
general-purpose language, it can be used to build almost any type of application with
the right tools/libraries. Additionally, python supports objects, modules, threads,
exception-handling, and automatic memory management which help in modeling
real-world problems and building applications to solve these problems.

2. What are the benefits of using Python?

e Python is a general-purpose programming language that has a simple, easy-to-


learn syntax that emphasizes readability and therefore reduces the cost of
program maintenance. Moreover, the language is capable of scripting, is
completely open-source, and supports third-party packages encouraging
modularity and code reuse.
e |ts high-level data structures, combined with dynamic typing and dynamic
binding, attract a huge community of developers for Rapid Application
Development and deployment.

Page 7 © Copyright by Interviewbit


Roo InterviewBit Python Interview Questions

3. What is a dynamically typed language?


Before we understand a dynamically typed language, we should learn about what
typing is. Typing refers to type-checking in programming languages. In a strongly-
typed language, such as Python, "1" + 2 will result in a type error since these
languages don't allow for "type-coercion" (implicit conversion of data types). On the
other hand, a weakly-typed language, such as Javascript, will simply output "12" as
result.
Type-checking can be done at two stages -

e Static - Data Types are checked before execution.


e Dynamic - Data Types are checked during execution.
Python is an interpreted language, executes each statement line by line and thus
type-checking is done on the fly, during execution. Hence, Python is a Dynamically
Typed Language.

Bb, InterviewBit

Statically Typed Dynamically Typed

4. What is an Interpreted language?

Page 8 © Copyright by Interviewbit


ROS InterviewBit Python Interview Questions

An Interpreted language executes its statements line by line. Languages such as


Python, Javascript, R, PHP, and Ruby are prime examples of Interpreted languages.
Programs written in an interpreted language runs directly from the source code, with
no intermediary compilation step.

5. What is PEP 8 and why Is it important?


PEP stands for Python Enhancement Proposal. A PEP is an official design document
providing information to the Python community, or describing a new feature for
Python or its processes. PEP 8 is especially important since it documents the style
guidelines for Python Code. Apparently contributing to the Python open-source
community requires you to follow these style guidelines sincerely and strictly.

6. What is Scope in Python?


Every object in Python functions within a scope. A scope is a block of code where an
object in Python remains relevant. Namespaces uniquely identify all the objects
inside a program. However, these namespaces also have a scope defined for them
where you could use their objects without any prefix. A few examples of scope
created during code execution in Python are as follows:

e Alocal scope refers to the local objects available in the current function.
e A global scope refers to the objects available throughout the code execution
since their inception.
e A module-level scope refers to the global objects of the current module
accessible in the program.
e An outermost scope refers to all the built-in names callable in the program. The
objects in this scope are searched last to find the name referenced.
Note: Local scope objects can be synced with global scope objects using keywords
such as global.

7. What are lists and tuples? What is the key difference between
the two?

Page 9 © Copyright by Interviewbit


ROS InterviewBit Python Interview Questions

Lists and Tuples are both sequence data types that can store a collection of objects
in Python. The objects stored in both sequences can have different data types. Lists
are represented with square brackets ['sara', 6, 9.19] , while tuples are
represented with parantheses ('ansh', 5, 0.97)
But what is the real difference between the two? The key difference between the two
is that while lists are mutable, tuples on the other hand are immutable objects.
This means that lists can be modified, appended or sliced on the go but tuples
remain constant and cannot be modified in any manner. You can run the following
example on Python IDLE to confirm the difference:

my_tuple = ('sara', 6, 5, 0.97)


my_list = ['sara', 6, 5, 0.97]
print(my_tuple[0]) # output => 'sara'
print(my_list[0]) # output => 'sara'
my_tuple[@0] = 'ansh' # modifying tuple => throws an error
my_list[0] = '‘ansh' # modifying list => list modified
print(my_tuple[0]) # output => 'sara'
print(my_list[0]) # output => '‘ansh'

8. What are the common built-in data types in Python?


There are several built-in data types in Python. Although, Python doesn't require data
types to be defined explicitly during variable declarations type errors are likely to
occur if the knowledge of data types and their compatibility with each other are
neglected. Python provides type() and _ isinstance() functions to check the type
of these variables. These data types can be grouped into the following categories-

e None Type:
None keyword represents the null values in Python. Boolean equality
operation can be performed using these NoneType objects.

Class Name Description

NoneType Represents the NULL values in Python.

Page 10 © Copyright by Interviewbit


e , : :
Cox xm tales)
avs (SVB tLe Python Interview Questions

e Numeric Types:
There are three distinct numeric types - integers, floating-point numbers, and
complex numbers. Additionally, booleans are a sub-type of integers.

Class Name Description

Stores integer literals including hex, octal and


int . .
binary numbers as integers

Stores literals containing decimal values


float and/or exponent signs as floating-point
numbers

Stores complex numbers in the form (A + Bj)


complex
and has attributes: real and imag

bool Stores boolean value (True or False).

Note: The standard library also includes fractions to store rational numbers and
decimal to store floating-point numbers with user-defined precision.

e Sequence Types:
According to Python Docs, there are three basic Sequence Types - lists, tuples,
and range objects. Sequence typeshavethe in and not in operators
defined for their traversing their elements. These operators share the same
priority as the comparison operations.

Page 11 © Copyright by Interviewbit

You might also like