Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda