Q21. What are the all ways, by which you can import a module in Python?
Ans: Python provides two ways by which you can import the Python module.
- Using import statement e.g. import math, it will give you an object of math module.
- Another way, import only, which you want from module e.g. from math import pi now you can use pi directly without dot notation.
Q22. How can I import the all the functions and variable from a module?
Ans: You can import everything from your module using * operator as below.
from math import *
However, this is a bad practice. It will overwrite all the variables and functions which you have defined in your program. So it is suggested, to avoid this.
Q23. What is function definition and function object?
Ans : Function definition, is the way by which you define a function as below.
Function Object: This is created by a function definition. Name of the function ‘total_course_durations’ is a variable, which points to function object.
Q24. What do you mean by function arguments and parameters?
Ans: Parameters are defined by the names that appear in a function definition, whereas arguments are the values actually passed to a function when calling it. Parameters define what types of arguments a function can accept. For example, given the function definition:
def func1(value1, value2=None, **kwargs):
Value1, value2 and kwargs are parameters of func1. However, when calling func1, for example:
func(100, value2=”hadoopexam”, new_name=anyvar)
the values 100, “hadoopexam” and anyvar are arguments.
Q25. What do you mean by local variables?
Ans: A variable which you define inside the function is known as local variable, you can not use local variable outside the function. Below two variables course1 and course2 are local and cannot be accessed outside the function.
Q26. What do you mean by module object?
Ans: A value created by an import statement that provides access to the values defined in a module.
e.g import math , here math is a module object and using dot notation you can access the variables defined in this module for instance math.pi
Q27. What is the encapsulation?
Ans: It is the process of transforming a sequence of statements into a function definition. Everything is encapsulated inside the function.
Q28. What is the docstring in python?
Ans: Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods.
An object's docstring is defined by including a string constant as the first statement in the object's definition.
"""Do nothing, but document it.
No, really, it doesn't do anything.
You can print this doc string using: print my_function.__doc__
Q29. Which operator will help you get the remainder and quotient value in Python?
Ans: There are two mathematical operator to help you get quotient and remainder.
Getting remainder using ‘%’ modulus operator and ‘/’ to get the quotient value for example
quotient = 10 / 3 # will result 3
remainder = 10 % 3 #will result 1
Q30. What all are the relational operators?
Ans: Below are all considered relational operator to do the comparison.
A !=B # A is not equal to B
A>B # A is greater than B
A<B # A is less than B
A>=B # A is greater and equal to B
A<=B #A is less than or equal to B