Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 20, 2018 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c4f26ba60bac3c8eece4bee115824304 to your computer and use it in GitHub Desktop.
Save parzibyte/c4f26ba60bac3c8eece4bee115824304 to your computer and use it in GitHub Desktop.
Combinar **kwargs y **args created by parzibyte - https://repl.it/@parzibyte/Combinar-kwargs-y-args
"""
Explicar **kwargs en Python con una
función
@author parzibyte
"""
def conectar(nombre, *numeros, **opciones):
print("Hola, ", nombre)
for numero in numeros:
print(numero)
host = opciones.get("host", "localhost")
puerto = opciones.get("puerto", "27017")
usuario = opciones.get("usuario",
"root?") # Aunque root no existe en MongoDB, creo
palabra_secreta = opciones.get("palabra_secreta", "123")
nombre_base_de_datos = opciones.get("nombre_base_de_datos", "test")
print(
"Host: {}, puerto: {}, usuario: {}, palabra_secreta: {}, nombre_base_de_datos: {}"
.format(host, puerto, usuario, palabra_secreta, nombre_base_de_datos))
conectar("Luis", 1, 2, 3, 4, usuario="parzibyte", palabra_secreta="hunter2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment