python tutorial - Python interview questions and answers - learn python - python programming
python interview questions :111
What is PEP8?
- PEP8 consists of coding guidelines for Python language so that programmers can write readable code making it easy to use for any other person, later on.
python interview questions :112
Is all the memory freed when Python exits?
- No it is not, because the objects that are referenced from global namespaces of Python modules are not always de-allocated when Python exits.
python interview questions :113
What does _init_.py do?
- _init_.py :Is an empty py file used for importing a module in a directory. _init_.py provides an easy way to organize the files.
- If there is a module maindir/subdir/module.py,_init_.py is placed in all the directories so that the module can be imported using the following command-
python interview questions :114
What is the different between range () and xrange () functions in Python?
- range () returns a list whereas xrange () returns an object that acts like an iterator for generating numbers on demand.
python interview questions :115
How can you randomize the items of a list in place in Python?
- Shuffle (lst) can be used for randomizing the items of a list in Python
Learn python - python tutorial - python randomize - python examples - python programs
python interview questions :116
What is a pass in Python?
- Pass in Python signifies a no operation statement indicating that nothing is to be done.
Learn python - python tutorial - python pass statement - python examples - python programs
python interview questions :117
If you are gives the first and last names of employees, which data type in Python will you use to store them?
- You can use a list that has first name and last name included in an element or use Dictionary.
- There are various data types in Python. Some of the important types are listed below.
- Python Numbers
- Python List
- Python Tuple
- Python Strings
- Python Set
- Python Dictionary
Learn python - python tutorial - python-dictionarys - python examples - python programs
python interview questions :118
What happens when you execute the statement mango=banana in Python?
- A name error will occur when this statement is executed in Python.
Learn python - python tutorial - python errors executed - python examples - python programs
python interview questions :119
Optimization for Python Code?
- Use builtin functions and libraries: Builtin functions like map() are implemented in C code. So the interpreter doesn’t have to execute the loop, this gives a considerable speedup.
- The map() function applies a function to every member of iterable and returns the result. If there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables.
Learn python - python tutorial - python-dictionarys - python examples - python programs
Output
python interview questions :120
What is monkey patching in Python?
- Monkey patching is a technique that helps the programmer to modify or extend other code at runtime.
- Monkey patching comes handy in testing but it is not a good practice to use it in production environment as debugging the code could become difficult.