Forem

Cristian Fernando
Cristian Fernando

Posted on

2

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

Explica este código Python

Dificultad: Básico

## Reto #49
frutas= ["manzana", "pera", "fresa"]
frutas.extend("uva")
print(frutas)
Enter fullscreen mode Exit fullscreen mode

👉 A. ['uva', 'manzana', 'pera', 'fresa']
👉 B. ['manzana', 'pera', 'fresa', ['uva']]
👉 C. ['manzana', 'pera', 'fresa', 'uva']
👉 D. ['manzana', 'pera', 'fresa', 'u', 'v', 'a']


Respuesta en el primer comentario.

Top comments (2)

Collapse
 
duxtech profile image
Cristian Fernando • Edited

Respuesta:
👉 D. ['manzana', 'pera', 'fresa', 'u', 'v', 'a']

El método extend en Python lo usamos para unir listas, pero ¿qué pasa cuando intentamos unir una lista con, por ejemplo, una cadena de texto?

extend va recorriendo item por item toda la lista, al llegar a uva se da cuenta que es un iterable de tipo cadena, entonces empieza a recorrer carácter por carácter todo el string y por ello el resultado es el mostrado.

Collapse
 
ilosamart profile image
Fábio Tramasoli

D

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay