JN0-224 practice question 1 of 15

You want to use a Python package or module. In this scenario, which statement would accomplish this task?

Full set: 66 questions
Answer options
A: reap
B: dir
C: input
D: Import Correct answer
Correct Answer:
D. Import
Explanation

In Python, the import statement is used to make code from one module available in another. When the interpreter encounters an import statement, it imports the specified module. This allows the current script to access the functions, classes, and variables defined within that module. For example, to use the Junos PyEZ library to manage a device, you would start your script with an import statement like from jnpr.junos import Device. This is a fundamental concept for creating modular and reusable code.

Why Incorrect

A. reap: This is not a standard Python keyword or built-in function for importing modules or packages.
B. dir: The dir() function is used for introspection; it returns a list of the names in the current local scope or the attributes of an object.
C. input: The input() function is used to read a line of text from standard input (usually the user), not for loading modules.

References

1. The Python Language Reference (Official Vendor Documentation): "The basic import statement (no from clause) is executed in two steps: 1. find a module, loading and initializing it if necessary 2. define a name or names in the local namespace for the scope where the import statement occurs."

Source: The Python Software Foundation, "The Python Language Reference", Version 3.12.3.

Section: 8.5. The import statement.

2. Juniper PyEZ Library Documentation (Official Vendor Documentation): Every example of using the PyEZ library begins with an import statement to make the library's components available. For instance, from jnpr.junos import Device.

Source: Juniper Networks TechLibrary, "PyEZ - Python for Junos OS".

Section: Getting Started > Example: Retrieving Device Facts.

3. MIT OpenCourseWare (University Courseware): "To use a module, you must first import it. The simplest way is with an import statement."

Source: MIT OpenCourseWare, "6.0001 Introduction to Computer Science and Programming in Python, Fall 2016".

Section: Lecture 5 Notes, page 2.

Scroll to Top