April 18, 2024, 1 p.m. | Cristian Fernando

DEV Community dev.to


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"))


👉 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 …

beginners programming python spanish text

Senior Machine Learning Engineer

@ GPTZero | Toronto, Canada

ML/AI Engineer / NLP Expert - Custom LLM Development (x/f/m)

@ HelloBetter | Remote

Doctoral Researcher (m/f/div) in Automated Processing of Bioimages

@ Leibniz Institute for Natural Product Research and Infection Biology (Leibniz-HKI) | Jena

Seeking Developers and Engineers for AI T-Shirt Generator Project

@ Chevon Hicks | Remote

Principal Data Architect - Azure & Big Data

@ MGM Resorts International | Home Office - US, NV

GN SONG MT Market Research Data Analyst 11

@ Accenture | Bengaluru, BDC7A