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.

def total_course_durations(c1,c2):

    training=curse_duration()

    training.hours=c1.hours+c2.hours

    training.minutes=c1.minutes+c2.minutes

    training.seconds=c1.seconds+c2.seconds

    return training

 

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:

Learn Python in Less than 8 Hours sitting at Home/@Desk

 

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.

def total_course_durations(c1,c2):

      course1=c1

      course2=c2

 

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam