Question:medium

What is pickling in Python?

Updated On: Jan 16, 2026
  • It is used to deserialize objects, i.e., converting the byte stream to object hierarchy.
  • It is used to serialize objects, i.e., to convert Python object hierarchy to byte stream.
  • It is used to move the file pointer to a specific location.
  • It is used in exception handling.
Show Solution

The Correct Option is B

Solution and Explanation

In Python, pickling serializes objects by converting a Python object hierarchy into a byte stream. This stream can then be saved to a file or sent over a network. The `pickle` module facilitates these operations:
  • Serialization (Pickling): Transforms a Python object into a byte stream using `pickle.dump()` for file output or `pickle.dumps()` for string output. This enables storage and transmission.
  • Deserialization (Unpickling): Reconstructs the original Python object from a byte stream using functions such as `pickle.load()` or `pickle.loads()`.
FunctionDescription
pickle.dump(obj, file)Serializes `obj` to the `file` object.
pickle.dumps(obj)Serializes `obj` to a byte stream.
pickle.load(file)Deserializes a byte stream from `file` into a Python object.
pickle.loads(bytes_obj)Deserializes `bytes_obj` into a Python object.
Pickling's main use is to store Python objects in files or transmit them over networks, preserving their state and structure for efficient data handling and inter-process communication.
Therefore, it is used to serialize objects, converting a Python object hierarchy into a byte stream.
Was this answer helpful?
0


Questions Asked in CUET (UG) exam