Avatar ·

Is it possible to initialize class variables from a dictionary. Python3.8

📁 dictionary, Advanced Python Topics, example, AI

Is it possible to somehow assign the values passed to each variable in the class from a dictionary. For example, the class has variables: a, b, c, d, and I pass a dictionary to the class constructor:

dictionary = {'b': 5, 'a': 2, 'c': 45}

The constructor should access the class variables by the dictionary key names and set these values to them, while the keys can be arbitrary.

class expain: def __init__