2

I found this code in a sample program:

>>> monitor = {'top': 5, 'left': 0, 'width': 1000, 'height': 200}
>>> output = 'sct-{top}x{left}_{width}x{height}.png'.format(**monitor)
>>> print(output)
sct-5x0_1000x200.png

It looks like .format(**monitor) is a **kwargs 'kind of thing', but I haven't used these things before.

I 'lifted' this code and know how it works, but can my understanding here land me in a kwargmire?

I was about to post this question but ran this first:

>>> '{} {} buckle my {top}'.format(1, 2, **monitor)
'1 2 buckle my 5'

and so I guess I can now say I've actively worked with kwargs.

CopyPasteIt
  • 532
  • 1
  • 8
  • 22

0 Answers0