4.8.3.5. Recap

The use case will determine which parameters to use in the function definition:

**def** f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):

As guidance:

>>> help(list.insert)
Help on method_descriptor:

insert(self, index, object, /)
    Insert object before index.

>>> wh = [1, 2]
>>> wh.insert(0, 'what')
>>> print(wh)
['what', 1, 2]

the standard module called json can take Python data hierarchies, and convert them to string representations; this process is called serializing. Reconstructing the data from the string representation is called deserializing. Between serializing and deserializing, the string representing the object may have been stored in a file or data, or sent over a network connection to some distant machine.

Note

The JSON format is commonly used by modern applications to allow for data exchange. Many programmers are already familiar with it, which makes it a good choice for interoperability.

Note   JSON files must be encoded in UTF-8. Use encoding="utf-8" when opening JSON file as a text file for both of reading and writing.

This simple serialization technique can handle lists and dictionaries, but serializing arbitrary class instances in JSON requires a bit of extra effort. The reference for the json module contains an explanation of this.

See also

pickle - the pickle module