Interview Question For Python
Interview Question For Python
Question
2. What is PEP 8?
Pickle module accepts any Python object and converts it into a string
representation and dumps it into a file by using dump function, this process is
called pickling. While the process of retrieving original Python objects from
the stored string representation is called unpickling.
A namespace is a naming system used to make sure that names are unique
to avoid naming conflicts.
6. What is PYTHONPATH?
Pickle module accepts any Python object and converts it into a string
representation and dumps it into a file by using dump function, this process is
called pickling. While the process of retrieving original Python objects from
the stored string representation is called unpickling.
In Python, the capitalize() method capitalizes the first letter of a string. If the
string already consists of a capital letter at the beginning, then, it returns the
original string.
11. What are the supported data types in Python?
Numbers
String
List
Tuple
Dictionary
Python’s dictionaries are kind of hash table type. They work like associative
arrays or hashes found in Perl and consist of key-value pairs. A dictionary key
can be almost any Python type, but are usually numbers or strings.
These methods belong to Python RegEx ‘re’ module and are used to modify
strings.
Pickling is the process of converting Python objects, such as lists, dicts, etc.,
into a character stream. This is done using a module named ‘pickle’, hence
the name pickling.
The process of retrieving the original Python objects from the stored string
representation, which is the reverse of the pickling process, is called
unpickling.
All programming languages have some way of defining the scope and extent
of the block of codes; in Python, it is indentation. Indentation provides better
readability to the code, which is probably why Python has made it
compulsory.
Python does not have a specific syntax for including multiline comments like
other programming languages. However, programmers can use triple-quoted
strings (docstrings) for making multiline comments as when a docstring is not
used as the first statement inside a method, it gets ignored by Python parser.
f= open(“hello.txt”, “wt”)
There are 3 main keywords i.e. try, except and finally which are used to catch
exceptions and handle the recovering mechanism accordingly. Try is the
block of a code which is monitored for errors. Except block gets executed
when an error occurs.
The beauty of the final block is to execute the code after trying for error. This
block gets executed irrespective of whether an error occurred or not. Finally
block is used to do the required cleanup activities of objects/variables.
As Python is an interpreter, it starts reading the code from the source file and
starts executing them.
Time module can be used to calculate the time at different stages of your
application and use the Logging module to log data to a file system in any
preferred format.
23. Does the same Python code work on multiple platforms without
any changes?
Yes. As long as you have the Python environment on your target platform
(Linux, Windows, Mac), you can run the same code.
24. How can you create a GUI based application in Python for client-
side functionality?
Python along with standard library Tkinter can be used to create GUI based
applications. Tkinter library supports various widgets which can create and
handle events which are widget specific.