Q10. Explain how can you make a Python Script executable on UNIX?
Ans. To make a Python Script executable on UNIX, you need to do two things
Q11. Explain how can you access a module written in Python from C?
Ans. You can access a module written in Python from C by following method,
Module = =PyImport_ImportModule("<modulename>");
Q12. Mention the use of // operator in Python?
Ans. It is a Floor Division operator, which is used for dividing two operands with the result as quotient showing only digits before the decimal point. For instance,
10//5 = 2 and 10.0//5.0 = 2.0.
Q13. What does this mean: *args, **kwargs? And why would we use it?
Ans. We use *args when we aren’t sure how many arguments are going to be passed to a function, or if we want to pass a stored list or tuple of arguments . to a function. **kwargs is used when we don’t know how many keyword arguments will be passed to a function, or it can be used to pass the values . of a dictionary as keyword arguments. The identifiers args and kwargs are a convention, you could also use *bob and **billy but that would not be, wise.
Q14. What is the Difference between Python 3 and Python 2 ?
Ans.
Python2 | Python3 |
It is more stable and transparent version of python programming language. | It is future of Python designed to address the design flawn in the previous versions. |
The print syntax is treated as a statement rather than a function that requires text to be wrapped in parenthesis. | The print is explicitly treated as a function and replaced by the print() function in Python 3 which requires an extra pair of parenthesis. |
ASCII string type is used by default to store strings. | Unicode is the implicit string type by default. |
It simply returns an integer to the nearest whole number when dividing two integers. | It makes integer division more intuitive by using true division for integers and floats. |
xrange function reconstructs the sequence every time. | xrange is replaced by range() function in Python 3. |
Q15. What is Enumerate() Function in Python?
Ans. The Python enumerate() function adds a counter to an iterable object. enumerate() function can accept sequential indexes starting from zero.