This article is about a pretty useful built-in module in Python, pprint.
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a well-formatted and more readable way!
In Python, pprint is a module that provides a "pretty printer" for displaying complex data structures such as lists, dictionaries, and tuples. The pprint module can be used to format and display data in a more readable and organized way, making it easier to understand and debug the data structures.
The pprint module can be imported by using the following command:
import pprint
The pprint module provides a single function, pprint, which takes a data structure as an argument and pretty prints it in a more readable format. For example, the following code:
import pprint data = {'key1': {'nested_key1': 'value1', 'nested_key2': 'value2'}, 'key2': [1, 2, 3, 4, 5], 'key3': (6, 7, 8, 9, 10)} pprint.pprint(data)
will produce the following output:
{'key1': {'nested_key1': 'value1', 'nested_key2': 'value2'}, 'key2': [1, 2, 3, 4, 5], 'key3': (6, 7, 8, 9, 10)}
As you can see, the pprint module formats the data in a more readable way, with nested structures indented and each element of a list or tuple on a new line.
Overall, the pprint module is a useful tool for displaying complex data structures in a more organized and readable format, which can be helpful for debugging and understanding code.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.