python tutorial - Python scripting interview questions - learn python - python programming
python interview questions :211
What is Python?
- Python is an interpreted language. Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby.
- Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that. You can do things like x=111 and then x="I'm a string" without error.
- Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++'s public, private), the justification for this point is given as "we are all adults here"
- In Python, functions are first-class objects. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects
- Writing Python code is quick but running it is often slower than compiled languages.
python interview questions :212
How to Merge two sorted list?
If you have two sorted lists, and you want to write a function to merge the two lists into one sorted list:
a = [3, 4, 6, 10, 11, 18]
b = [1, 5, 7, 12, 13, 19, 21]
while a and b:
output:
python interview questions :213
How to use map, filter, and reduce?
Using map, filter, reduce, write a code that create a list of (n)**2 for range(10) for even integers:
Output:
python interview questions :214
What is Hamming Distance ?
The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different:
Learn python - python tutorial - python-hamming-distance - python examples - python programs
python interview questions :215
What is the difference between an expression and a statement in Python?
Expression only contain identifiers, literals and operators, where operators include arithmetic and boolean operators, the function call operator () the subscription operator [] and similar, and can be reduced to some kind of "value", which can be any Python object. Examples:
On the other hand, are everything that can make up a line (or several lines) of Python code. Note that expressions are statements as well. Examples:
python interview questions :216
What is difference in os.popen and subprocess.Popen?
The os process functionality is considered obsolete. The subprocess module was introduced in Python 2.4 as a unified, more powerful replacement for several older modules and functions related to subprocesses. They are listed here:
os.popen
was deprecated in Python 2.6 (but, interestingly, it is not deprecated in Python 3, where it is implemented in terms of subprocess.Popen). There is a paragraph in the documentation on on how to replace it with subprocess.Popen.
Learn python - python tutorial - pythone-boolean - python examples - python programs
python interview questions :217
In python, what is a method_descriptor?
The method_descriptor is a normal class with __ get __, __ set __ and __ del __ methods. You can check the link for more info at Static vs instance methods of str in Python
python interview questions :218
How to use Python type() - function ?
If a single argument (object) is passed to type() built-in, it returns type of the given object. If three arguments (name, bases and dict) are passed, it returns a new type object.
Output:
python interview questions :219
In Python, what is the best way to execute a local Linux command stored in a string?
In Python, what is the simplest way to execute a local Linux command stored in a string while catching any potential exceptions that are thrown and logging the output of the Linux command and any caught errors to a common log file.
Learn python - python tutorial - python-testing-flask - python examples - python programs
python interview questions :220
Python, compute list differenceS?
Use list comprehensions if you do:
Learn python - python tutorial - python-print-hello - python examples - python programs