An instance of an Python dictionary with a string

  • 2020-05-24 05:42:47
  • OfStack

The dictionary is converted to a string


if __name__ == '__main__':
  a = {'a' : 1, 'b' : 2, 'c' : 3}
  b = str(a)
  print(type(b))

The output result is:

< class 'str' >

---------------------------------------------------------------

String conversion to dictionary


if __name__ == '__main__':
  a = "{'a' : 1, 'b' : 2, 'c' : 3}"
  b = eval(a)
  print(type(b))

The output result is:

< class 'dict' >


Related articles: