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

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US