Python Modules & Packaging

    Last Updated :
    Discuss
    Comments

    Question 1

    What is the main purpose of using modules in Python?

    • To avoid using classes

    • To write programs in Java

    • To organize reusable code in separate files

    • To increase the speed of the Python interpreter

    Question 2

    What will the following code output?

    Python
    import math
    print(math.pi)
    


    • 3.14159…

    • math.pi

    • Error

    • pi

    Question 3

    Which of the following imports only the sqrt function from the math module?

    • import math.sqrt

    • from math import sqrt

    • import sqrt from math

    • import sqrt

    Question 4

    What is the effect of using an alias when importing a module in Python?

    • It hides the module

    • It speeds up execution

    • It gives the module a shorter name

    • It disables built-in functions

    Question 5

    Why is “from math import *” discouraged in large programs?

    • It increases performance

    • It increases typing

    • It can cause name conflicts

    • It hides the source of code

    Question 6

    What happens if you try to import a module that doesn’t exist?

    • The program continues silently

    • A warning is shown

    • An ImportError is raised

    • A file is created

    Question 7

    Which of these commands installs the virtualenv tool using pip?

    • pip load virtualenv

    • pip get virtualenv

    • pip install virtualenv

    • install virtualenv pip

    Question 8

    How do you create a virtual environment named my_env using virtualenv?

    • python my_env.py

    • virtualenv create my_env

    • virtualenv my_env

    • new virtualenv my_env

    Question 9

    What command activates a virtual environment on Windows?

    • source my_env/bin/activate

    • Scripts\activate

    • activate my_env.sh

    • run my_env/activate

    Question 10

    After activating a virtual environment, how do you install Django version 1.9 into it?

    • install Django=1.9

    • pip install Django==1.9

    • python get Django 1.9

    • pip add Django:1.9

    There are 12 questions to complete.

    Take a part in the ongoing discussion