Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
What does **D mean in string.format(**D)? [double]

I can't figure out what **D means in the following codes:

 >>> D = {'say': 5, 'get': 'shrubbery'} >>> '%(say)s => %(get)s' % D '5 => shrubbery' >>> '{say} => {get}'.format(**D) '5 => shrubbery'

I googled **kwargs in python and most of the results talk about allowing functions to take an arbitrary number of keyword arguments.

The string.format(**D) here doesn't look like something that would allow the function to take an arbitrary number of keyword arguments because I see that the dictionary type variable D is just one argument. But what does it mean here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's called argument unpacking.
**D is used to unpack arguments. Expands the dictionary into a sequence of keyword assignments, so...

 '{say} => {get}'.format(**D)

becomes...

 '{say} => {get}'.format(say = 5, get = shrubbery)

The **kwargs trick works because keyword arguments are dictionaries .

I leave you a link if you want to know more about the subject https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!