
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















































**1. How will you improve the performance of a program in Python?
reference?
11. What is the difference between List and Dictionary data types in
Python?
**12. What are the different built-in data types available in Python?
Java?
**18. How do you perform unit testing for Python code?
**42. What is the difference between โisโ and โ==โ in Python?
data type will you use to store it in Python?
This book contains basic to expert level Python interview questions that an interviewer asks. Each question is accompanied with an answer so that you can prepare for job interview in short time.
We have compiled this list after attending dozens of technical interviews in top-notch companies like- Google, Facebook, Netflix, Amazon etc.
Often, these questions and concepts are used in our daily programming work. But these are most helpful when an Interviewer is trying to test your deep knowledge of Python.
The difficulty rating on these Questions varies from a Fresher level software programmer to a Senior software programmer.
Once you go through them in the first pass, mark the questions that you could not answer by yourself. Then, in second pass go through only the difficult questions.
After going through this book 2-3 times, you will be well prepared to face a technical interview on Python for an experienced programmer.
Python is strong that even Google uses it. Some of the benefits of using Python are as follows:
i. Efficient : Python is very efficient in memory management. For a large data set like Big Data, it is much easier to program in Python. ii. Faster : Though Python code is interpreted, still Python has very fast performance. iii. Wide usage : Python is widely used among different organizations for different projects. Due to this wide usage, there are thousands of add-ons available for use with Python. iv. Easy to learn : Python is quite easy to learn. This is the biggest benefit of using Python. Complex tasks can be very easily implemented in Python.
By default, every source code file in Python is in UTF-8 encoding. But we can also specify our own encoding for source files. This can be done by adding following line after #! line in the source file.
In the above line we can replace encoding with the encoding that we want to use.
Pickling is a process by which a Python object hierarchy can be converted into a byte stream. The reverse operation of Pickling is Unpickling.
Python has a module named pickle. This module has the implementation of a powerful algorithm for serialization and de-serialization of Python object structure.
Some people also call Pickling as Serialization or Marshalling.
With Serialization we can transfer Python objects over the network. It is also used in persisting the state of a Python object. We can write it to a file or a database.
There is a private heap space in Python that contains all the Python objects and data structures. In CPython there is a memory manager responsible for managing the heap space.
There are different components in Python memory manager that handle segmentation, sharing, caching, memory pre-allocation etc.
Python memory manager also takes care of garbage collection by using Reference counting algorithm.
In Python, Tuple and List are built-in data structures.
Some of the differences between Tuple and List are as follows:
I. Syntax : A Tuple is enclosed in parentheses: E.g. myTuple = (10, 20, โappleโ); A List is enclosed in brackets: E.g. myList = [10, 20, 30];
II. Mutable : Tuple is an immutable data structure. Whereas, a List is a mutable data structure.
III. Size : A Tuple takes much lesser space than a List in Python.
IV. Performance : Tuple is faster than a List in Python. So it gives us good performance.
V. Use case : Since Tuple is immutable, we can use it in cases like Dictionary creation. Whereas, a List is preferred in the use case where data can alter.
A Python Decorator is a mechanism to wrap a Python function and modify its behavior by adding more functionality to it. We can use @ symbol to call a Python Decorator function.
Main differences between List and Dictionary data types in Python are as follows:
I. Syntax : In a List we store objects in a sequence. In a Dictionary we store objects in key-value pairs.
II. Reference : In List we access objects by index number. It starts from 0 index. In a Dictionary we access objects by key specified at the time of Dictionary creation.
III. Ordering : In a List objects are stored in an ordered sequence. In a Dictionary objects are not stored in an ordered sequence.
IV. Hashing : In a Dictionary, keys have to be hashable. In a List there is no need for hashing.
Some of the built-in data types available in Python are as follows:
Numeric types : These are the data types used to represent numbers in Python.
int: It is used for Integers
long: It is used for very large integers of non-limited length.
float: It is used for decimal numbers.
complex: This one is for representing complex numbers
Sequence types: These data types are used to represent sequence of characters or objects.
str: This is similar to String in Java. It can represent a sequence of characters.
bytes: This is a sequence of integers in the range of 0-255.
byte array: like bytes, but mutable (see below); only available in Python 3.x
list: This is a sequence of objects.
tuple: This is a sequence of immutable objects.
Sets : These are unordered collections.
set: This is a collection of unique objects.
frozen set: This is a collection of unique immutable objects.
Mappings : This is similar to a Map in Java.
A Namespace in Python is a mapping between a name and an object. It is currently implemented as Python dictionary.
E.g. the set of built-in exception names, the set of built-in names, local names in a function
At different moments in Python, different Namespaces are created. Each Namespace in Python can have a different lifetime.
For the list of built-in names, Namespace is created when Python interpreter starts.
When Python interpreter reads the definition of a module, it creates global namespace for that module.
When Python interpreter calls a function, it creates local namespace for that function.
We can use following ways to concatenate multiple string together in Python:
I. use + operator:
E.g. >>> fname="John" >>> lname="Ray" >>> print fname+lname JohnRay
II. use join function:
E.g. >>> ''.join(['John','Ray']) 'JohnRay'