Computer Science
Assertion (A): Python modules are .py files that contain Python code.
Reasoning (R): The import statement allows you to import all the functions from a module into your code.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Python Modules
1 Like
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
A module is created as a python (.py) file containing a collection of function definitions, classes and variables. The import statement can be used to import a module. It is the simplest and most common way to use modules in our code. It provides access to all attributes (like variables, constants etc) and methods or functions present in the module.
Answered By
2 Likes
Related Questions
Assertion (A): The median() method returns the middle value of numeric data in a list.
Reasoning (R): The math module contains both mathematical and statistical functions.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Python has a built-in math module that you can use for mathematical tasks.
Reasoning (R): The mean() method calculates the arithmetic mean of the numbers in a list using math module.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): The output of print(math.factorial(4.5)) shall generate an error.
Reasoning (R): This factorial() function belongs to the statistics module in Python.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What is a Python library? Explain with examples.