DEV Community

Cover image for Ibuprofeno.py💊| #180: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on

Ibuprofeno.py💊| #180: Explica este código Python

Explica este código Python

Dificultad: Fácil

c = 'hello'
print(c.center(10,'1'))
Enter fullscreen mode Exit fullscreen mode
  • A. 1hello
  • B. 11hello111
  • C. 111111hello111111
  • D. hello1

Respuesta:

👉 B. 11hello111

El método center de python recibe dos parámetros, el primero cuantos caracteres tendrá la cadena resultante luego de aplicarlo y le segundo con que cadena completaremos los espacios hasta llegar el número del primer parámetro.

En nuestro caso la palabra hello tiene 5 caracteres, por tanto necesitamos rellenar 5 mas para poder llegar a 10.

Este relleno se hace repitiendo n veces el segundo parámetro hasta llegar en nuestro ejemplo a 10.

La cadena original obviamente queda "centrada" al final.

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more