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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay