Skip to content
HackoryWEB SECURITY ACADEMYProgramming

Unit 05 · Textos y sus métodos · Lesson 04

Buscar texto con in

in pregunta si un texto aparece dentro de otro.

Lesson content is in Spanish.

Python in your browser

The first time, Python downloads about 5 MB (only once; then it stays saved). If you can, use Wi-Fi.

Python is already saved in this browser: it will not download again.

Python downloads when you start reading.
  1. 01Understand
  2. 02Try
  3. 03Explain

The situation

Algunos mensajes de los clientes dicen urgente y otros piden envío. El programa los puede detectar solo, sin que nadie lea cada mensaje.

Understand each piece

  • in

    "urgente" in mensaje responde si la palabra aparece dentro del mensaje.

  • True y False

    Son las dos respuestas posibles de una pregunta: True significa verdadero y False, falso. Se escriben así, con mayúscula y sin comillas.

  • Mayúsculas

    in distingue mayúsculas: "urgente" in "URGENTE" da False. Si pasás el mensaje a minúsculas con lower() antes de preguntar, no importa cómo lo escribieron.

Example

mensaje = "Pedido urgente: 2 cuadernos"
print("urgente" in mensaje)
print("mochila" in mensaje)

La primera pregunta da True porque urgente aparece en el mensaje. La segunda da False porque no dice mochila.

Before moving on: what will happen?

¿Qué va a mostrar este programa?
mensaje = "URGENTE: 2 cuadernos"
print("urgente" in mensaje)

Your mission

Detectá los pedidos urgentes

La prueba crea la variable mensaje. Mostrá dos líneas: si el mensaje dice urgente y si dice envío, sin importar las mayúsculas. Con mensaje = "Pedido URGENTE con envío", la salida es: ¿Es urgente? True ¿Pide envío? True

  1. Pasá el mensaje a minúsculas: texto = mensaje.lower().
  2. Preguntá "urgente" in texto y "envío" in texto.
  3. Guardá cada respuesta en una variable, por ejemplo urgente = "urgente" in texto, y mostrala con f"¿Es urgente? {urgente}".

If you get stuck

One hint at a time: the first points the way and the last almost solves it.

The key idea

in pregunta si un texto está dentro de otro y responde True o False. Distingue mayúsculas, así que conviene usar lower() antes.

Solve with help

If you have already tried, you can see a reference solution. The lesson is marked as solved with help and adds no XP.