PCPP1 practice question 7 of 10
Select the true statements about the json.-dumps () function. (Select two answers.)
Full set: 45 questionsThe json.dumps() function is used for serialization, which is the process of converting a Python object into a JSON formatted string. The function's name itself, "dump string," indicates its purpose. It takes a Python data structure (like a dictionary or list) as its primary argument and returns a str object representing that data in JSON format. This process is essential for storing data or transmitting it over a network in a standardized, language-independent format.
B. It returns a Python entity. This describes the deserialization function json.loads(), which parses a JSON string and converts it back into a Python object.
C. It takes a JSON string as its argument. This is also a description of json.loads(), which requires a JSON-formatted string as input for deserialization.
1. Official Python Documentation: The documentation for the json module explicitly states, "Serialize obj to a JSON formatted str using this conversion table." This confirms that the function takes a Python object (obj) as an argument (D) and returns a JSON formatted string (A).
Source: Python Software Foundation. (2023). json — JSON encoder and decoder. Python 3.12.0 documentation. Retrieved from https://docs.python.org/3/library/json.html#json.dumps, Section: json.dumps.
2. University Courseware (MIT OpenCourseWare): In the lecture notes for "Introduction to Computer Science and Programming in Python," the process of using the json library is detailed. The examples show json.dumps() being called with a Python dictionary as an argument to produce a string, reinforcing that it takes Python data and returns a string.
Source: Guttag, J. V. (2016). Introduction to Computation and Programming Using Python, With Application to Understanding Data (2nd ed.). MIT Press. Chapter 10, Section 10.2, "Reading and Writing Files". (While the book is a primary source, its principles are reflected in MIT OCW course 6.0001 materials which cover file I/O and data structures).
3. University Courseware (University of Michigan): The "Python for Everybody" course materials, widely adopted by universities, explain that json.dumps() is used to "take a Python data structure and put it into a string." This directly supports both correct answers.
Source: Severance, C. R. (2016). Python for Everybody: Exploring Data in Python 3. Chapter 13: Web Services and XML. Section: "Parsing JSON".
Keep practicing
Take the free PCPP1 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCPP1 practice questions
- Question 1Select the true statements about the connection-oriented and connectionless types of comm…
- Question 2Select the true statements about the sqlite3 module. (Select two answers.)
- Question 4Select the true statements about the sqirte3 module. (Select two answers.)
- Question 5If w is a correctly created main application window, which method would you use to foe bo…
- Question 9Select the true statements related to PEP 8 naming conventions. (Select two answers.)
- Question 10Select the true statement related to PEP 257.
