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

Cristian Fernando - Sep 16 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player