1. Open a Python interpreter. Python can show you the set of currently known nam
ID: 3706566 • Letter: 1
Question
1.
Open a Python interpreter. Python can show you the set of currently known names if you type (dir()). While these values may vary from interpreter to interpreter, you should always have( __name__) available.
What is the value of( __name__ )in a Python interpreter?
2.In order to install a package (pandas), what command would you use with (pip)? (Please use only single spaces between words in the response, and do not include the prompt $.)
3.If you want an automatic testing framework like (pytest) to work with your code, what should you prefix test functions with (five characters)?
Explanation / Answer
NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.
1. Open a Python interpreter. Python can show you the set of currently known names if you type (dir()). While these values may vary from interpreter to interpreter, you should always have( __name__) available.
What is the value of( __name__ )in a Python interpreter?
Ans)
Unix Terminal> python3
Python 3.6.4 (default, Mar 9 2018, 23:15:12)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>>
Explanation:
1) Every module in python has a special attribute variable called __name__.
2) The value of __name__ attribute is set to '__main__' which is considered as starting point of program execution.
3) The value of __name__ is set to __main__ when it is run as main program. Other than main program if we see the value of __name__ is set to contain the name of the module.
2. In order to install a package (pandas), what command would you use with (pip)? (Please use only single spaces between words in the response, and do not include the prompt $.)
Ans)
Explanation:
1) pandas can be installed in python using pip command.
2) The command for installing pandas is as follows.
pip install pandas
3) pip will identify all the required dependencies for pandas and install them as well. It is an easy way to install the required packages.
3. If you want an automatic testing framework like (pytest) to work with your code, what should you prefix test functions with (five characters)?
Ans)
Explanation:
1) pytest framework is used to test applications written in python. It provides easy interface to write from small to complex test cases for functions and libraries.
2) As a convention for prefixing test function we will use "test_" before any test function written in pytest framework.
Example:
# content of test_sample.py program
def dec(x):
return x - 1
def test_answer():
assert dec(4) == 3
Here in the above code the function dec(x) is tested in test_answer using assert statement to see if function return its value properly.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.