4

If the my_dict variable is global, you can't do:

my_dict = {}

that just create a new reference in the local scope.

Also, I found disgusting using the global keyword, so how can I empty a dict using its methods?

codeforester
  • 34,080
  • 14
  • 96
  • 122
Juanjo Conti
  • 27,061
  • 38
  • 104
  • 130

4 Answers4

8

Use the clear() method?

Documentation - (docs.python.org)

Josh Crozier
  • 219,308
  • 53
  • 366
  • 287
Tao
  • 407
  • 2
  • 5
3

you mean like .clear() ?

pycruft
  • 61,251
  • 1
  • 17
  • 11
1
my_dict.clear()
Richard Fearn
  • 24,169
  • 6
  • 56
  • 55
1

my_dict.clear()

ngroot
  • 1,166
  • 5
  • 11