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

Explica este código Python

Dificultad: Intermedio

def f(text, target_word, replace_word): index_target_word = text.find(target_word) x = text[0:index_target_word] y = text[index_target_word + len(target_word):len(text)] return f"{x}{replace_word}{y}" print(f("Keep calm and write Python", "write", "enjoy"))
Enter fullscreen mode
Exit fullscreen mode

👉 A. Keep calm and write Python
👉 B. Keep calm and enjoy Python
👉 C. IndexError
👉 D. TypeError


Respuesta:

👉 B. Keep calm and enjoy Python
La función f implementa un algoritmo para buscar y remplazar una palabra dada por otra sin el uso de la función replace de Python.

Usando find() y dividiendo la cadena podemos lograr lo que se pretende.


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Furthermore, bing webmaster tools provide insightful data about a website’s backlinks. We build and design custom websites that are aesthetically pleasing and functional. Study your competitors’ websites and social media channels.