<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tu codigo cotidiano</title>
    <description>The latest articles on DEV Community by Tu codigo cotidiano (@tu_codigocotidiano_f173d).</description>
    <link>https://dev.to/tu_codigocotidiano_f173d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3375057%2Ffa90e872-13fe-4a57-b3d6-e75515a50879.png</url>
      <title>DEV Community: Tu codigo cotidiano</title>
      <link>https://dev.to/tu_codigocotidiano_f173d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tu_codigocotidiano_f173d"/>
    <language>en</language>
    <item>
      <title>How to Organize Python Code with Modules and Packages — A Practical Beginner Guide</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Thu, 03 Sep 2026 15:54:20 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/how-to-organize-python-code-with-modules-and-packages-a-practical-beginner-guide-4cp5</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/how-to-organize-python-code-with-modules-and-packages-a-practical-beginner-guide-4cp5</guid>
      <description>&lt;p&gt;A Python program can work perfectly and still become difficult to maintain.&lt;/p&gt;

&lt;p&gt;That usually happens when one file slowly starts doing everything:&lt;/p&gt;

&lt;p&gt;program.py&lt;/p&gt;

&lt;p&gt;├── register expenses&lt;br&gt;
├── save CSV files&lt;br&gt;
├── calculate totals&lt;br&gt;
├── generate reports&lt;br&gt;
└── run the program&lt;/p&gt;

&lt;p&gt;Nothing is necessarily broken.&lt;/p&gt;

&lt;p&gt;The problem is that finding and changing one responsibility starts requiring you to understand several unrelated parts of the file.&lt;/p&gt;

&lt;p&gt;The first useful question&lt;/p&gt;

&lt;p&gt;When a Python project grows, don't start by asking:&lt;/p&gt;

&lt;p&gt;How many lines should a file have?&lt;/p&gt;

&lt;p&gt;A better question is:&lt;/p&gt;

&lt;p&gt;Which responsibilities belong together, and which ones should be able to change separately?&lt;/p&gt;

&lt;p&gt;For example, an expense tracker could evolve from one large file into:&lt;/p&gt;

&lt;p&gt;expense_tracker/&lt;br&gt;
├── main.py&lt;br&gt;
└── finance/&lt;br&gt;
    ├── &lt;strong&gt;init&lt;/strong&gt;.py&lt;br&gt;
    ├── expenses.py&lt;br&gt;
    ├── files.py&lt;br&gt;
    └── reports.py&lt;/p&gt;

&lt;p&gt;Now the structure itself tells us something:&lt;/p&gt;

&lt;p&gt;expenses.py handles expense logic.&lt;/p&gt;

&lt;p&gt;files.py handles persistence.&lt;/p&gt;

&lt;p&gt;reports.py handles calculations and summaries.&lt;/p&gt;

&lt;p&gt;main.py coordinates the program.&lt;/p&gt;

&lt;p&gt;That is the real value of modules and packages: they help the code communicate its structure.&lt;/p&gt;

&lt;p&gt;A tiny example&lt;/p&gt;

&lt;p&gt;Instead of keeping every function in main.py, we can create a module:&lt;/p&gt;

&lt;h1&gt;
  
  
  file: finance/expenses.py
&lt;/h1&gt;

&lt;p&gt;def add_expense(expenses, date, category, amount):&lt;br&gt;
    expenses.append({&lt;br&gt;
        "date": date,&lt;br&gt;
        "category": category,&lt;br&gt;
        "amount": amount&lt;br&gt;
    })&lt;/p&gt;

&lt;p&gt;Then use it from another file:&lt;/p&gt;

&lt;h1&gt;
  
  
  file: main.py
&lt;/h1&gt;

&lt;p&gt;from finance.expenses import add_expense&lt;/p&gt;

&lt;p&gt;expenses = []&lt;/p&gt;

&lt;p&gt;add_expense(&lt;br&gt;
    expenses,&lt;br&gt;
    "2026-09-02",&lt;br&gt;
    "Food",&lt;br&gt;
    18000&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;The behavior is simple, but the important change is architectural:&lt;/p&gt;

&lt;p&gt;the responsibility now has a clear home.&lt;/p&gt;

&lt;p&gt;The mistake to avoid&lt;/p&gt;

&lt;p&gt;Learning modules doesn't mean creating one file for every function.&lt;/p&gt;

&lt;p&gt;This:&lt;/p&gt;

&lt;p&gt;calculator/&lt;br&gt;
├── add.py&lt;br&gt;
├── subtract.py&lt;br&gt;
├── multiply.py&lt;br&gt;
└── divide.py&lt;/p&gt;

&lt;p&gt;is not automatically better than:&lt;/p&gt;

&lt;p&gt;calculator.py&lt;/p&gt;

&lt;p&gt;More files do not always mean better organization.&lt;/p&gt;

&lt;p&gt;The goal is not fragmentation.&lt;/p&gt;

&lt;p&gt;The goal is clarity.&lt;/p&gt;

&lt;p&gt;Want the full visual walkthrough?&lt;/p&gt;

&lt;p&gt;I wrote a complete step-by-step guide in Spanish on TuCódigoCotidiano.&lt;/p&gt;

&lt;p&gt;It covers:&lt;/p&gt;

&lt;p&gt;modules and packages;&lt;/p&gt;

&lt;p&gt;import;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;init&lt;/strong&gt;.py;&lt;/p&gt;

&lt;p&gt;if &lt;strong&gt;name&lt;/strong&gt; == "&lt;strong&gt;main&lt;/strong&gt;";&lt;/p&gt;

&lt;p&gt;absolute and relative imports;&lt;/p&gt;

&lt;p&gt;circular imports;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pycache&lt;/strong&gt;;&lt;/p&gt;

&lt;p&gt;when to split code — and when not to.&lt;/p&gt;

&lt;p&gt;👉 Read the complete guide:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/modulos-y-paquetes-organiza-tu-codigo-sin-perderte/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/modulos-y-paquetes-organiza-tu-codigo-sin-perderte/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're moving from small Python scripts to projects with multiple files, this is exactly the transition the guide is designed to explain.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>¿Qué ocurre realmente cuando ejecutas un contenedor Docker?</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Mon, 31 Aug 2026 15:10:41 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/que-ocurre-realmente-cuando-ejecutas-un-contenedor-docker-5396</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/que-ocurre-realmente-cuando-ejecutas-un-contenedor-docker-5396</guid>
      <description>&lt;h1&gt;
  
  
  ¿Qué ocurre realmente cuando ejecutas un contenedor Docker?
&lt;/h1&gt;

&lt;p&gt;Escribes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unos segundos después nginx está funcionando.&lt;/p&gt;

&lt;p&gt;Puede parecer que Docker acaba de crear una pequeña computadora dentro de tu computador.&lt;/p&gt;

&lt;p&gt;Pero eso no es realmente lo que ocurre.&lt;/p&gt;

&lt;h2&gt;
  
  
  Todo comienza con una imagen
&lt;/h2&gt;

&lt;p&gt;Docker necesita una imagen que contenga los elementos necesarios para ejecutar la aplicación.&lt;/p&gt;

&lt;p&gt;Las imágenes normalmente están construidas mediante capas.&lt;/p&gt;

&lt;p&gt;Eso permite reutilizar partes que ya existen en el sistema y evita descargar o almacenar todo nuevamente.&lt;/p&gt;

&lt;h2&gt;
  
  
  Después aparece el contenedor
&lt;/h2&gt;

&lt;p&gt;Docker utiliza la imagen como base y crea un entorno donde ejecutará la aplicación.&lt;/p&gt;

&lt;p&gt;Aquí aparece una diferencia fundamental:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;una imagen y un contenedor no son lo mismo.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;La imagen es reutilizable.&lt;/p&gt;

&lt;p&gt;El contenedor es una instancia creada a partir de ella.&lt;/p&gt;

&lt;h2&gt;
  
  
  En el fondo hay procesos
&lt;/h2&gt;

&lt;p&gt;En Linux, un contenedor no necesita ejecutar un sistema operativo completo independiente.&lt;/p&gt;

&lt;p&gt;La aplicación se ejecuta como uno o varios procesos que comparten el kernel del host.&lt;/p&gt;

&lt;p&gt;Entonces, ¿cómo consigue Docker que parezca un entorno independiente?&lt;/p&gt;

&lt;h2&gt;
  
  
  Namespaces: aislamiento
&lt;/h2&gt;

&lt;p&gt;Linux dispone de mecanismos llamados namespaces.&lt;/p&gt;

&lt;p&gt;Gracias a ellos, un proceso puede tener una visión aislada de elementos como:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;procesos&lt;/li&gt;
&lt;li&gt;interfaces de red&lt;/li&gt;
&lt;li&gt;puntos de montaje&lt;/li&gt;
&lt;li&gt;usuarios&lt;/li&gt;
&lt;li&gt;hostname&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Para la aplicación, parece que existe dentro de su propio entorno.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cgroups: controlar recursos
&lt;/h2&gt;

&lt;p&gt;También necesitamos evitar que un contenedor consuma todos los recursos de la máquina.&lt;/p&gt;

&lt;p&gt;Para eso Linux dispone de los cgroups.&lt;/p&gt;

&lt;p&gt;Permiten gestionar y contabilizar recursos como:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU&lt;/li&gt;
&lt;li&gt;memoria&lt;/li&gt;
&lt;li&gt;entrada y salida&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Docker utiliza estos mecanismos para aplicar límites a los contenedores.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Qué ocurre con la red?
&lt;/h2&gt;

&lt;p&gt;Docker también puede crear redes virtuales.&lt;/p&gt;

&lt;p&gt;Por ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 8080:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aquí estamos indicando que el tráfico recibido en el puerto 8080 del host pueda llegar al puerto 80 utilizado por nginx dentro del contenedor.&lt;/p&gt;

&lt;h2&gt;
  
  
  ¿Y los datos?
&lt;/h2&gt;

&lt;p&gt;Un contenedor puede eliminarse.&lt;/p&gt;

&lt;p&gt;Pero nuestros datos muchas veces deben sobrevivir.&lt;/p&gt;

&lt;p&gt;Para eso existen los volúmenes.&lt;/p&gt;

&lt;p&gt;Los volúmenes permiten almacenar información fuera de la capa efímera del contenedor.&lt;/p&gt;

&lt;p&gt;Son especialmente importantes cuando trabajamos con bases de datos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Entonces, ¿qué hay detrás de &lt;code&gt;docker run&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Podemos visualizarlo así:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IMAGEN
   ↓
PROCESO
   ↓
AISLAMIENTO
   ↓
CONTROL DE RECURSOS
   ↓
RED
   ↓
ALMACENAMIENTO
   ↓
CONTENEDOR
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker hace que toda esta coordinación parezca sencilla.&lt;/p&gt;

&lt;p&gt;Y esa es precisamente una de sus mayores virtudes.&lt;/p&gt;

&lt;p&gt;🎧 En &lt;strong&gt;Tu Código Cotidiano&lt;/strong&gt; preparé un episodio corto explicando todo este recorrido:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;¿Qué ocurre dentro de Docker cuando ejecutas un contenedor?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/que-ocurre-dentro-de-docker-cuando-ejecutas-un-contenedor/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/que-ocurre-dentro-de-docker-cuando-ejecutas-un-contenedor/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fff8hr1ic617gh008bu0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fff8hr1ic617gh008bu0m.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>linux</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tu programa funciona… pero olvida todo: persistencia de datos con Python</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Thu, 27 Aug 2026 20:16:50 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/tu-programa-funciona-pero-olvida-todo-persistencia-de-datos-con-python-516n</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/tu-programa-funciona-pero-olvida-todo-persistencia-de-datos-con-python-516n</guid>
      <description>&lt;h1&gt;
  
  
  Tu programa funciona… pero olvida todo
&lt;/h1&gt;

&lt;p&gt;Imagina que estás creando un pequeño programa en Python para registrar gastos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;gastos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="n"&gt;gastos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;categoria&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Comida&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;valor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18000&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gastos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Todo funciona.&lt;/p&gt;

&lt;p&gt;Pero cierras el programa, lo ejecutas nuevamente y &lt;code&gt;gastos&lt;/code&gt; vuelve a estar vacío.&lt;/p&gt;

&lt;p&gt;¿Por qué?&lt;/p&gt;

&lt;p&gt;Porque tener información dentro de una variable no significa haberla guardado permanentemente.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memoria no es persistencia
&lt;/h2&gt;

&lt;p&gt;Mientras nuestro programa está ejecutándose puede trabajar con listas, diccionarios, números y otros objetos.&lt;/p&gt;

&lt;p&gt;Pero si queremos encontrar esa información después de cerrar el programa necesitamos representarla fuera de ese ciclo de ejecución.&lt;/p&gt;

&lt;p&gt;Una de las formas más sencillas de hacerlo es utilizando archivos.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;nota.txt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;archivo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;archivo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Mi primer dato persistente&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ahora la información puede continuar existiendo incluso después de que Python termine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tres letras importantes: r, w y a
&lt;/h2&gt;

&lt;p&gt;Cuando empezamos a trabajar con archivos hay tres modos especialmente útiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r → leer
w → escribir desde cero
a → añadir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hay que tener especial cuidado con &lt;code&gt;w&lt;/code&gt;: si el archivo ya contenía información, podemos reemplazarla.&lt;/p&gt;

&lt;p&gt;Si queremos añadir algo sin borrar lo anterior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;nota.txt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;archivo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;archivo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;Otra línea&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ¿TXT, CSV o JSON?
&lt;/h2&gt;

&lt;p&gt;Una forma sencilla de pensarlo es observar la estructura de nuestros datos.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TXT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Útil cuando queremos guardar texto sencillo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSV&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tiene sentido cuando nuestros datos se parecen a una tabla:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fecha,categoria,valor
2026-08-27,Comida,18000
2026-08-27,Transporte,6500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python incluye el módulo &lt;code&gt;csv&lt;/code&gt;, por lo que no necesitamos construir el archivo concatenando comas manualmente.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSON&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Empieza a resultar interesante cuando nuestros datos contienen claves, listas, números, booleanos o estructuras anidadas.&lt;/p&gt;

&lt;p&gt;La decisión no consiste simplemente en memorizar tres extensiones.&lt;/p&gt;

&lt;p&gt;Consiste en preguntarnos:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;¿qué forma tienen mis datos?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ese cambio de perspectiva hace mucho más sencillo entender la persistencia.&lt;/p&gt;

&lt;p&gt;Preparé una guía completa en español donde desarrollamos el recorrido desde memoria y archivos TXT hasta CSV y JSON, con ejemplos paso a paso:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/archivos-de-texto-csv-y-json-datos-que-sobreviven-al-programa/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/archivos-de-texto-csv-y-json-datos-que-sobreviven-al-programa/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Una frase resume bastante bien todo el concepto:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;El programa puede terminar. Los datos no tienen por qué desaparecer.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Python Didn't Crash. The Result Was Still Wrong.</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Wed, 26 Aug 2026 20:50:27 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/python-didnt-crash-the-result-was-still-wrong-30ck</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/python-didnt-crash-the-result-was-still-wrong-30ck</guid>
      <description>&lt;p&gt;One of the most dangerous bugs isn't a SyntaxError.&lt;/p&gt;

&lt;p&gt;It isn't an exception.&lt;/p&gt;

&lt;p&gt;It doesn't even produce a traceback.&lt;/p&gt;

&lt;p&gt;Sometimes Python executes your entire program successfully...&lt;/p&gt;

&lt;p&gt;…and gives you the wrong answer.&lt;/p&gt;

&lt;p&gt;Consider this:&lt;/p&gt;

&lt;p&gt;def calcular_total(precios, descuento):&lt;br&gt;
    subtotal = sum(precios)&lt;br&gt;
    total = subtotal - descuento&lt;br&gt;
    return total&lt;/p&gt;

&lt;p&gt;precios = [120000, 80000]&lt;br&gt;
descuento = 0.10&lt;/p&gt;

&lt;p&gt;print(calcular_total(precios, descuento))&lt;/p&gt;

&lt;p&gt;Expected:&lt;/p&gt;

&lt;p&gt;180000&lt;/p&gt;

&lt;p&gt;Actual:&lt;/p&gt;

&lt;p&gt;199999.9&lt;/p&gt;

&lt;p&gt;Python isn't broken.&lt;/p&gt;

&lt;p&gt;Our assumption is.&lt;/p&gt;

&lt;p&gt;And that's where debugging becomes much more interesting.&lt;/p&gt;

&lt;p&gt;A mistake I made when learning to debug was asking:&lt;/p&gt;

&lt;p&gt;“What should I print?”&lt;/p&gt;

&lt;p&gt;A better question is:&lt;/p&gt;

&lt;p&gt;“What do I need to observe to prove or reject my hypothesis?”&lt;/p&gt;

&lt;p&gt;That changes debugging from guessing into an experiment:&lt;/p&gt;

&lt;p&gt;Reproduce → Hypothesis → Measure → Evidence → Conclusion&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Are the inputs correct?&lt;br&gt;
Is subtotal correct?&lt;br&gt;
Is descuento what we expect?&lt;br&gt;
At which exact operation does the state become wrong?&lt;/p&gt;

&lt;p&gt;Once you know that:&lt;/p&gt;

&lt;p&gt;subtotal = 200000 ✓&lt;br&gt;
descuento = 0.10 ✓&lt;/p&gt;

&lt;p&gt;the search space becomes tiny.&lt;/p&gt;

&lt;p&gt;The suspicious operation is now:&lt;/p&gt;

&lt;p&gt;subtotal - descuento&lt;/p&gt;

&lt;p&gt;That's the real goal of debugging:&lt;/p&gt;

&lt;p&gt;Turn “something is wrong” into one small, testable question.&lt;/p&gt;

&lt;p&gt;I wrote a practical guide showing this process with print(), type(), repr(), breakpoint() and step-by-step state inspection.&lt;/p&gt;

&lt;p&gt;Full guide:&lt;br&gt;
&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/depuracion-aprende-a-encontrar-el-error-antes-de-culpar-a-python/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/depuracion-aprende-a-encontrar-el-error-antes-de-culpar-a-python/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>debugging</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Python Exceptions: From a Crashing Program to Controlled Error Handling</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Mon, 24 Aug 2026 23:50:50 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/python-exceptions-from-a-crashing-program-to-controlled-error-handling-4gbp</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/python-exceptions-from-a-crashing-program-to-controlled-error-handling-4gbp</guid>
      <description>&lt;p&gt;What should your Python program do when reality doesn’t follow the happy path?&lt;/p&gt;

&lt;p&gt;I published a new practical guide on errors and exceptions in Python.&lt;/p&gt;

&lt;p&gt;Instead of starting by memorizing try, except, else, and finally, the guide begins with a program that crashes because of unexpected input and builds the solution step by step.&lt;/p&gt;

&lt;p&gt;It covers traceback reading, ValueError, ZeroDivisionError, specific exception handling, else, finally, raise, common mistakes, and a final program that survives invalid input.&lt;/p&gt;

&lt;p&gt;The main idea:&lt;/p&gt;

&lt;p&gt;Exception handling is not about hiding errors. It is about designing what your program should do when something goes wrong.&lt;/p&gt;

&lt;p&gt;Full guide in Spanish:&lt;br&gt;
&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/errores-y-excepciones-en-python-evita-que-tu-programa-muera-en-el-intento/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/errores-y-excepciones-en-python-evita-que-tu-programa-muera-en-el-intento/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>De Ionic a PostgreSQL: qué ocurre realmente cuando creamos una tarea</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Tue, 18 Aug 2026 20:41:48 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/de-ionic-a-postgresql-que-ocurre-realmente-cuando-creamos-una-tarea-3co1</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/de-ionic-a-postgresql-que-ocurre-realmente-cuando-creamos-una-tarea-3co1</guid>
      <description>&lt;h1&gt;
  
  
  De Ionic a Posts una tarea
&lt;/h1&gt;

&lt;p&gt;Aprender Django, Angular o PostgreSQL por separado es relativamente sencillo.&lt;/p&gt;

&lt;p&gt;El verdadero salto ocurre cuando intentamos entender &lt;strong&gt;cómo todas esas tecnologías colaboran dentro de una aplicación real&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Supongamos que tenemos una aplicación móvil para administrar tareas y el usuario pulsa:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Crear tarea&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;¿Qué ocurre después?&lt;/p&gt;

&lt;p&gt;La respuesta completa se parece a esto:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ionic / Angular
      ↓
   HTTP + JSON
      ↓
Django REST Framework
      ↓
   Django ORM
      ↓
PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1. Angular recoge la información
&lt;/h2&gt;

&lt;p&gt;El formulario mantiene temporalmente valores como:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;título;&lt;/li&gt;
&lt;li&gt;descripción;&lt;/li&gt;
&lt;li&gt;estado;&lt;/li&gt;
&lt;li&gt;fecha límite.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pero esos datos todavía no forman parte del estado permanente del sistema.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. El cliente construye una petición HTTP
&lt;/h2&gt;

&lt;p&gt;Angular utiliza un servicio para enviar los datos hacia nuestra API.&lt;/p&gt;

&lt;p&gt;El frontend no debería conectarse directamente a PostgreSQL.&lt;/p&gt;

&lt;p&gt;Su trabajo es solicitar una operación al backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Django REST Framework recibe el JSON
&lt;/h2&gt;

&lt;p&gt;Aquí comienza una de las partes más importantes.&lt;/p&gt;

&lt;p&gt;El servidor no debería confiar ciegamente en lo enviado desde la interfaz.&lt;/p&gt;

&lt;p&gt;Django REST Framework valida el contrato de la petición y permite que las reglas del dominio permanezcan centralizadas en el servidor.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. El backend aplica las reglas
&lt;/h2&gt;

&lt;p&gt;Una tarea puede tener, por ejemplo, solamente tres estados válidos:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pendiente;&lt;/li&gt;
&lt;li&gt;pospuesta;&lt;/li&gt;
&lt;li&gt;completada.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;También podemos implementar reglas como:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;identificar tareas próximas a vencer;&lt;/li&gt;
&lt;li&gt;conservar información de auditoría;&lt;/li&gt;
&lt;li&gt;asignar usuarios;&lt;/li&gt;
&lt;li&gt;realizar eliminación lógica en lugar de destruir registros.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Estas decisiones pertenecen al dominio de la aplicación, no simplemente a la interfaz.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. El ORM persiste la información
&lt;/h2&gt;

&lt;p&gt;Una vez validada la operación, Django utiliza su ORM para escribir los cambios en PostgreSQL.&lt;/p&gt;

&lt;p&gt;Ahora sí existe una representación persistente de la tarea.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. La API responde
&lt;/h2&gt;

&lt;p&gt;Django REST Framework serializa nuevamente la entidad y devuelve JSON al cliente.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Ionic actualiza la interfaz
&lt;/h2&gt;

&lt;p&gt;Angular recibe la respuesta y actualiza el estado visible de la aplicación.&lt;/p&gt;

&lt;p&gt;Tenemos entonces un ciclo completo:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;interfaz → API → reglas → persistencia → API → interfaz&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Y esa misma arquitectura puede reutilizarse cuando llevamos la aplicación a Android utilizando Ionic y Capacitor.&lt;/p&gt;




&lt;p&gt;Construí un tutorial completo donde implementamos este proyecto paso a paso utilizando:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Django REST Framework&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Angular&lt;/li&gt;
&lt;li&gt;Ionic&lt;/li&gt;
&lt;li&gt;CaD, filtros, soft delete, auditoría, cambios de estado y tareas próximas a vencer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 &lt;strong&gt;Tutorial completo en español:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_tutoriales/construye-una-app-fullstack-con-django-rest-postgresql-angular-ionic-y-android/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_tutoriales/construye-una-app-fullstack-con-django-rest-postgresql-angular-ionic-y-android/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Si estás aprendiendo arquitectura fullstack, mi recomendación es que no te concentres únicamente en hacer funcionar cada tecnología.&lt;/p&gt;

&lt;p&gt;Intenta seguir &lt;strong&gt;el recorrido completo de una sola operación desde la pantalla hasta la base de datos y de vuelta&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ahí es donde muchas piezas empiezan a tener sentido.&lt;/p&gt;

</description>
      <category>django</category>
      <category>angular</category>
      <category>ionic</category>
      <category>postgres</category>
    </item>
    <item>
      <title>What Physically Happens When You Ask an AI a Question?</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Tue, 11 Aug 2026 22:18:14 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/what-physically-happens-when-you-ask-an-ai-a-question-5503</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/what-physically-happens-when-you-ask-an-ai-a-question-5503</guid>
      <description>&lt;p&gt;We often think about artificial intelligence as something purely digital.&lt;/p&gt;

&lt;p&gt;You type a question.&lt;/p&gt;

&lt;p&gt;Press Enter.&lt;/p&gt;

&lt;p&gt;A few seconds later, an answer appears.&lt;/p&gt;

&lt;p&gt;But physically, a surprising amount of infrastructure has been involved during those few seconds.&lt;/p&gt;

&lt;p&gt;Your question first travels through networking infrastructure toward a data center. There, the text is transformed into tokens that can be processed by an AI model.&lt;/p&gt;

&lt;p&gt;Specialized hardware—often GPUs or other accelerators—performs billions of mathematical operations to calculate what should come next.&lt;/p&gt;

&lt;p&gt;That computation requires electricity.&lt;/p&gt;

&lt;p&gt;Electricity produces heat.&lt;/p&gt;

&lt;p&gt;Heat requires cooling.&lt;/p&gt;

&lt;p&gt;And all of this happens while networking systems move information between your device, servers, memory, storage and computing accelerators.&lt;/p&gt;

&lt;p&gt;In other words, an AI response is not simply “generated by software.”&lt;/p&gt;

&lt;p&gt;It is the result of a physical chain involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Networks&lt;/li&gt;
&lt;li&gt;Data centers&lt;/li&gt;
&lt;li&gt;GPUs and accelerators&lt;/li&gt;
&lt;li&gt;Memory&lt;/li&gt;
&lt;li&gt;Electricity&lt;/li&gt;
&lt;li&gt;Cooling systems&lt;/li&gt;
&lt;li&gt;Large-scale distributed computing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recently explored this idea in a new episode of &lt;strong&gt;TuCodigoCotidiano&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;🎧 &lt;strong&gt;¿Qué ocurre físicamente cuando le preguntas algo a una IA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/que-ocurre-fisicamente-cuando-le-preguntas-algo-a-una-ia/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/que-ocurre-fisicamente-cuando-le-preguntas-algo-a-una-ia/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The episode is in Spanish and focuses on understanding the physical infrastructure behind something we now do every day: asking an AI a question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhud5otruqn02kh58ug9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhud5otruqn02kh58ug9u.png" alt=" " width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  ai #machinelearning #computerscience #technology
&lt;/h1&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>technology</category>
    </item>
    <item>
      <title>Build a Personal Expense Tracker in Python: From Fundamentals to a Real Terminal App</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Tue, 28 Jul 2026 12:06:08 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/build-a-personal-expense-tracker-in-python-from-fundamentals-to-a-real-terminal-app-375m</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/build-a-personal-expense-tracker-in-python-from-fundamentals-to-a-real-terminal-app-375m</guid>
      <description>&lt;p&gt;Learning Python syntax is one thing.&lt;/p&gt;

&lt;p&gt;Using variables, conditionals, loops, lists, dictionaries, and functions &lt;strong&gt;together to build an actual program&lt;/strong&gt; is where things start to become much more interesting.&lt;/p&gt;

&lt;p&gt;I published a new step-by-step project in &lt;strong&gt;TuCodigoCotidiano&lt;/strong&gt; where we build a personal expense tracker that runs entirely in the terminal.&lt;/p&gt;

&lt;p&gt;The guide is written in Spanish and is designed for people who already know the basic Python concepts but want to understand how those pieces fit together inside a real application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we build
&lt;/h2&gt;

&lt;p&gt;The project starts small.&lt;/p&gt;

&lt;p&gt;A single expense becomes a dictionary.&lt;/p&gt;

&lt;p&gt;Multiple expenses become a list of dictionaries.&lt;/p&gt;

&lt;p&gt;Then we gradually add functions until the program can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Register income&lt;/li&gt;
&lt;li&gt;Register expenses&lt;/li&gt;
&lt;li&gt;Display transactions&lt;/li&gt;
&lt;li&gt;Calculate total income&lt;/li&gt;
&lt;li&gt;Calculate total expenses&lt;/li&gt;
&lt;li&gt;Calculate the current balance&lt;/li&gt;
&lt;li&gt;Group expenses by category&lt;/li&gt;
&lt;li&gt;Validate user input&lt;/li&gt;
&lt;li&gt;Run through an interactive terminal menu&lt;/li&gt;
&lt;li&gt;Save data to JSON&lt;/li&gt;
&lt;li&gt;Load previous data when the program starts again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The final structure is intentionally simple:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;problem → data → functions → interaction → validation → persistence → application&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;No classes.&lt;/p&gt;

&lt;p&gt;No database.&lt;/p&gt;

&lt;p&gt;No external libraries.&lt;/p&gt;

&lt;p&gt;Just Python and the standard library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I built the tutorial this way
&lt;/h2&gt;

&lt;p&gt;A common beginner experience is learning concepts independently:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;lists&lt;/p&gt;

&lt;p&gt;dictionaries&lt;/p&gt;

&lt;p&gt;functions&lt;/p&gt;

&lt;p&gt;But knowing those concepts does not automatically explain &lt;strong&gt;how to design a program&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So instead of starting with a large finished script, the project begins with a practical question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What would a program need to do to help you understand where your money is going?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From there, every new piece of code solves one specific part of the problem.&lt;/p&gt;

&lt;p&gt;The goal is not only to finish an expense tracker.&lt;/p&gt;

&lt;p&gt;The goal is to understand how a real program grows from a simple idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the complete project
&lt;/h2&gt;

&lt;p&gt;🐍 &lt;strong&gt;Construye un gestor de gastos personales en la terminal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/construye-un-gestor-de-gastos-personales-en-la-terminal/#del-problema-cotidiano-al-programa" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/construye-un-gestor-de-gastos-personales-en-la-terminal/#del-problema-cotidiano-al-programa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The complete tutorial is in Spanish and includes the code, explanations, visual diagrams, validation, JSON persistence, testing ideas, common mistakes, and challenges to extend the project.&lt;/p&gt;

&lt;p&gt;If you were extending this project, what would you build next: budgets, dates, search, editing transactions, or something else?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsneuoc70die4u73oupda.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsneuoc70die4u73oupda.jpeg" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Electromagnetic Spectrum: The Invisible Infrastructure Behind Our Connected World</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Mon, 27 Jul 2026 14:13:34 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/the-electromagnetic-spectrum-the-invisible-infrastructure-behind-our-connected-world-3kon</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/the-electromagnetic-spectrum-the-invisible-infrastructure-behind-our-connected-world-3kon</guid>
      <description>&lt;p&gt;Before getting out of bed, you have probably already used one of the most important infrastructures in the modern world.&lt;/p&gt;

&lt;p&gt;You checked your phone, received a message, or connected to Wi-Fi.&lt;/p&gt;

&lt;p&gt;None of those actions would be possible without the &lt;strong&gt;electromagnetic spectrum&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  An invisible network around us
&lt;/h2&gt;

&lt;p&gt;Radio, Wi-Fi, Bluetooth, mobile networks, television, satellite communications, and many navigation systems use specific regions of the electromagnetic spectrum.&lt;/p&gt;

&lt;p&gt;Although these technologies may appear unrelated, they all transmit information using electromagnetic waves.&lt;/p&gt;

&lt;p&gt;What changes between them is mainly their frequency, wavelength, transmission power, and method of encoding information.&lt;/p&gt;

&lt;p&gt;Even visible light belongs to this same family. Our eyes simply detect a very small portion of a much larger spectrum.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequencies as invisible lanes
&lt;/h2&gt;

&lt;p&gt;Imagine hundreds of people speaking inside the same room at the same time.&lt;/p&gt;

&lt;p&gt;Without separate conversations, turns, or channels, understanding anyone would become extremely difficult.&lt;/p&gt;

&lt;p&gt;Something similar happens with wireless communications.&lt;/p&gt;

&lt;p&gt;Different services use different frequency bands to reduce interference. Mobile networks, aviation, emergency services, weather systems, radio stations, and satellites must operate under carefully coordinated rules.&lt;/p&gt;

&lt;p&gt;These frequencies work like invisible lanes through which information travels.&lt;/p&gt;

&lt;p&gt;Some frequencies can cover long distances and pass through obstacles more effectively. Others can carry larger amounts of information but require more antennas or clearer paths between transmitter and receiver.&lt;/p&gt;

&lt;h2&gt;
  
  
  Internet is not a magical cloud
&lt;/h2&gt;

&lt;p&gt;Wireless signals are only one part of the journey.&lt;/p&gt;

&lt;p&gt;After reaching an antenna, information may continue through base stations, fiber-optic cables, data centers, and satellite links.&lt;/p&gt;

&lt;p&gt;Fiber optics also use electromagnetic radiation, transmitting information through pulses of light.&lt;/p&gt;

&lt;p&gt;The connected world therefore combines two major routes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Electromagnetic waves travelling through the air.&lt;/li&gt;
&lt;li&gt;Light pulses travelling through fiber-optic cables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they support everything from everyday messages to aircraft navigation, weather alerts, emergency communications, and space exploration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Listen to the episode
&lt;/h2&gt;

&lt;p&gt;In this Spanish-language episode of &lt;strong&gt;TuCódigoCotidiano&lt;/strong&gt;, Javier and Laura explore the electromagnetic spectrum and explain why it can be understood as the invisible infrastructure of modern society.&lt;/p&gt;

&lt;p&gt;🎧 Listen here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/el-espectro-electromagnetico-la-infraestructura-invisible/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/escuchar-podcast/el-espectro-electromagnetico-la-infraestructura-invisible/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cities have visible roads for vehicles and electromagnetic roads for information.&lt;/p&gt;

&lt;p&gt;Although we cannot see them, their design determines how connected, secure, and resilient our society can become.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3xxspnz32demzbxgh26b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3xxspnz32demzbxgh26b.jpg" alt=" " width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>telecommunications</category>
      <category>networking</category>
      <category>science</category>
      <category>podcast</category>
    </item>
    <item>
      <title>Python Functions for Beginners: Stop Repeating Code and Start Reusing Solutions</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Fri, 24 Jul 2026 14:10:27 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/python-functions-for-beginners-stop-repeating-code-and-start-reusing-solutions-2664</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/python-functions-for-beginners-stop-repeating-code-and-start-reusing-solutions-2664</guid>
      <description>&lt;p&gt;Copying a few lines of code may seem harmless.&lt;/p&gt;

&lt;p&gt;But what happens when the same instructions appear three, five, or ten times throughout your program?&lt;/p&gt;

&lt;p&gt;A small change suddenly requires editing several places. One forgotten copy may behave differently from the others, and the program becomes harder to understand and maintain.&lt;/p&gt;

&lt;p&gt;This is one of the problems that functions help us solve.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If a task appears several times, it probably needs a name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A function turns a group of related instructions into a reusable solution that we can execute whenever we need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with repeated code
&lt;/h2&gt;

&lt;p&gt;Imagine that we need to calculate the total price of several purchases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;product_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;notebook&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;price_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8500&lt;/span&gt;
&lt;span class="n"&gt;quantity_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;total_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price_1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity_1&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;quantity_1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; units of &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product_1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; cost $&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;product_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pencil&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;price_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;
&lt;span class="n"&gt;quantity_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;total_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price_2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity_2&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;quantity_2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; units of &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product_2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; cost $&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_2&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program works, but the same procedure is repeated:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive a product.&lt;/li&gt;
&lt;li&gt;Receive its price.&lt;/li&gt;
&lt;li&gt;Receive a quantity.&lt;/li&gt;
&lt;li&gt;Calculate the total.&lt;/li&gt;
&lt;li&gt;Display the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of copying that procedure every time, we can create a function and give the task a descriptive name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a function with &lt;code&gt;def&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In Python, a function definition begins with the &lt;code&gt;def&lt;/code&gt; keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello! Welcome to Python.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This definition contains several important parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;def&lt;/code&gt; tells Python that we are defining a function.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;greet&lt;/code&gt; is the function name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;()&lt;/code&gt; contains the function parameters.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:&lt;/code&gt; marks the beginning of the function body.&lt;/li&gt;
&lt;li&gt;The indented instructions belong to the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Defining a function does not execute it automatically.&lt;/p&gt;

&lt;p&gt;To run its instructions, we must call it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello! Welcome to Python.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each call executes the function body again.&lt;/p&gt;

&lt;p&gt;This distinction is essential:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A function definition describes a task. A function call asks Python to perform it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Parameters and arguments
&lt;/h2&gt;

&lt;p&gt;Our first function always displays the same message.&lt;/p&gt;

&lt;p&gt;To make it work with different values, we can add a parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;. Welcome to Python.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laura&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Carlos&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sofia&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; is a &lt;strong&gt;parameter&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"Laura"&lt;/code&gt;, &lt;code&gt;"Carlos"&lt;/code&gt;, and &lt;code&gt;"Sofia"&lt;/code&gt; are &lt;strong&gt;arguments&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A parameter represents the information that a function expects to receive.&lt;/p&gt;

&lt;p&gt;An argument is the actual value provided when the function is called.&lt;/p&gt;

&lt;p&gt;The same function can therefore process different data without changing its internal instructions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using multiple parameters
&lt;/h2&gt;

&lt;p&gt;A function can receive more than one value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; units of &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; cost $&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;notebook&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pencil&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python matches positional arguments with parameters according to their order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"notebook" → product
8500       → price
3          → quantity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this reason, both the number and order of the arguments matter.&lt;/p&gt;

&lt;p&gt;The calculation logic now exists in only one place. We can reuse it with as many products as necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Returning results with &lt;code&gt;return&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The previous function displays the calculated total.&lt;/p&gt;

&lt;p&gt;But what happens when another part of the program needs to use that value?&lt;/p&gt;

&lt;p&gt;This is where &lt;code&gt;return&lt;/code&gt; becomes important:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned value can be stored in a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;notebook_total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;pencil_total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notebook_total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pencil_total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can also participate in another operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;grand_total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;notebook_total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;pencil_total&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grand_total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A returned value is not limited to being displayed.&lt;/p&gt;

&lt;p&gt;The program can store it, compare it, transform it, send it to another function, or use it in a larger calculation.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;print()&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; are not the same
&lt;/h2&gt;

&lt;p&gt;This is one of the most important distinctions when learning Python functions.&lt;/p&gt;

&lt;p&gt;Consider these two examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both functions calculate the same value, but they do different things.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;show_double()&lt;/code&gt; displays the value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;show_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;calculate_double()&lt;/code&gt; returns the value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful way to remember the difference is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;print()&lt;/code&gt; communicates a value to the user.&lt;br&gt;
&lt;code&gt;return&lt;/code&gt; gives the value back to the program.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use &lt;code&gt;print()&lt;/code&gt; when the main purpose is to display information.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;return&lt;/code&gt; when the result must continue participating in the program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does a function return &lt;code&gt;None&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Every Python function call produces a result.&lt;/p&gt;

&lt;p&gt;When a function finishes without an explicit &lt;code&gt;return&lt;/code&gt;, Python automatically returns &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Consider this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;25500
None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function displayed &lt;code&gt;25500&lt;/code&gt;, but it did not return that number.&lt;/p&gt;

&lt;p&gt;Therefore, the value stored in &lt;code&gt;result&lt;/code&gt; is &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;None&lt;/code&gt; does not mean zero, an empty string, or an error.&lt;/p&gt;

&lt;p&gt;It represents the absence of a useful returned value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common beginner mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Forgetting the parentheses
&lt;/h3&gt;

&lt;p&gt;Writing the function name by itself refers to the function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding parentheses calls it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first expression identifies the function object. The second expression executes the function.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Sending the wrong number of arguments
&lt;/h3&gt;

&lt;p&gt;A function with three required parameters expects three corresponding arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This call is incomplete:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;notebook&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python will report an error because the &lt;code&gt;quantity&lt;/code&gt; argument is missing.&lt;/p&gt;

&lt;p&gt;The correct call is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;notebook&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Sending arguments in the wrong order
&lt;/h3&gt;

&lt;p&gt;Consider this function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This call uses the correct number of arguments but places them incorrectly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;show_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;notebook&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python will assign:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8500       → product
"notebook" → price
3          → quantity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The names of positional parameters do not automatically identify the arguments. Their position determines how Python assigns them.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Trying to calculate with a function that only prints
&lt;/h3&gt;

&lt;p&gt;This function displays a value but returns &lt;code&gt;None&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;show_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore, this operation will fail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;show_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function prints &lt;code&gt;10&lt;/code&gt;, but &lt;code&gt;result&lt;/code&gt; contains &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To reuse the calculated value, return it instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A practical example
&lt;/h2&gt;

&lt;p&gt;Let us create a function that calculates the price of a purchase after applying a discount:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_discounted_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;discount_percentage&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;discount_percentage&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
    &lt;span class="n"&gt;final_price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;final_price&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now use the same solution with different values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;first_product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_discounted_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;second_product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_discounted_price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;80000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;second_product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;90000.0
68000.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also combine the returned values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;purchase_total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;first_product&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;second_product&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;purchase_total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates the main advantage of &lt;code&gt;return&lt;/code&gt;: the results can continue moving through the program.&lt;/p&gt;

&lt;h2&gt;
  
  
  A better way to think about functions
&lt;/h2&gt;

&lt;p&gt;Functions are more than a Python syntax feature.&lt;/p&gt;

&lt;p&gt;They help us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Divide large problems into smaller tasks.&lt;/li&gt;
&lt;li&gt;Give meaningful names to those tasks.&lt;/li&gt;
&lt;li&gt;Avoid repeating instructions.&lt;/li&gt;
&lt;li&gt;Make changes in one place.&lt;/li&gt;
&lt;li&gt;Test individual pieces of logic.&lt;/li&gt;
&lt;li&gt;Reuse solutions with different data.&lt;/li&gt;
&lt;li&gt;Combine small solutions into larger programs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When deciding whether to create a function, ask:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Does this task appear more than once?&lt;/li&gt;
&lt;li&gt;Can I describe the task with a clear name?&lt;/li&gt;
&lt;li&gt;Which information does the task need?&lt;/li&gt;
&lt;li&gt;Should the function display something or return a result?&lt;/li&gt;
&lt;li&gt;Will another part of the program need the result?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These questions transform functions from a syntax exercise into a tool for designing better programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final challenge
&lt;/h2&gt;

&lt;p&gt;Create a function called &lt;code&gt;calculate_average&lt;/code&gt; that receives three grades and returns their average.&lt;/p&gt;

&lt;p&gt;Start with this structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_average&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grade_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;grade_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;grade_3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Write your solution here
&lt;/span&gt;    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then store the result and display it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;student_average&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_average&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;4.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student_average&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As an additional challenge, create another function that receives the average and returns either &lt;code&gt;"Passed"&lt;/code&gt; or &lt;code&gt;"Failed"&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continue learning
&lt;/h2&gt;

&lt;p&gt;I published a complete illustrated Spanish guide that explains these concepts with additional examples, practical exercises, and common mistakes:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/funciones-divide-los-problemas-y-reutiliza-soluciones/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/funciones-divide-los-problemas-y-reutiliza-soluciones/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What confused you the most when you first learned functions: parameters, arguments, &lt;code&gt;return&lt;/code&gt;, or &lt;code&gt;None&lt;/code&gt;?&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python Dictionaries and Sets: Organize Named Data and Remove Duplicates</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Tue, 21 Jul 2026 16:44:17 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/python-dictionaries-and-sets-organize-named-data-and-remove-duplicates-4kc4</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/python-dictionaries-and-sets-organize-named-data-and-remove-duplicates-4kc4</guid>
      <description>&lt;p&gt;When we start learning Python, lists are often one of the first data structures we use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laura&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Medellín&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works, but what does each position represent?&lt;/p&gt;

&lt;p&gt;We need to remember that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Position &lt;code&gt;0&lt;/code&gt; contains the name.&lt;/li&gt;
&lt;li&gt;Position &lt;code&gt;1&lt;/code&gt; contains the age.&lt;/li&gt;
&lt;li&gt;Position &lt;code&gt;2&lt;/code&gt; contains the city.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A dictionary provides a clearer alternative because every value is identified by a descriptive key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a dictionary
&lt;/h2&gt;

&lt;p&gt;A dictionary stores information as key-value pairs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laura&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;city&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Medellín&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of asking for the value at position &lt;code&gt;0&lt;/code&gt;, we can ask directly for the value associated with &lt;code&gt;"name"&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Laura
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful way to remember the difference is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A list position tells you where a value is. A dictionary key tells you what the value means.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Updating and adding information
&lt;/h2&gt;

&lt;p&gt;Python dictionaries are mutable, so their content can change after creation.&lt;/p&gt;

&lt;p&gt;To update an existing value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Keyboard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;price&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120000&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;price&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;110000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add a new key-value pair, use the same syntax with a key that does not exist yet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;available&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting dictionary is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Keyboard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;price&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;110000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;available&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Safely reading values with &lt;code&gt;get()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Using square brackets requires the key to exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;"email"&lt;/code&gt; is missing, Python raises a &lt;code&gt;KeyError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;get()&lt;/code&gt; method provides a safer alternative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It returns &lt;code&gt;None&lt;/code&gt; when the key is missing.&lt;/p&gt;

&lt;p&gt;You can also define a default value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Not registered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Not registered
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check whether a key exists, use the &lt;code&gt;in&lt;/code&gt; operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;city&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;city&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Keys, values, and pairs
&lt;/h2&gt;

&lt;p&gt;Python provides three useful dictionary methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;course&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python Basics&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;4 weeks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;format&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Online&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;course&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They provide different views of the same information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;keys()&lt;/code&gt; returns the keys.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;values()&lt;/code&gt; returns the stored values.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;items()&lt;/code&gt; returns complete key-value pairs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Looping through a dictionary
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;items()&lt;/code&gt; method is especially useful when working with a &lt;code&gt;for&lt;/code&gt; loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;capitals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Colombia&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bogotá&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Peru&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Lima&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Argentina&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Buenos Aires&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;country&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capital&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;capitals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;country&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;capital&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Colombia: Bogotá
Peru: Lima
Argentina: Buenos Aires
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During every iteration, Python assigns the current key to &lt;code&gt;country&lt;/code&gt; and its associated value to &lt;code&gt;capital&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a set?
&lt;/h2&gt;

&lt;p&gt;A set is a collection that stores unique values.&lt;/p&gt;

&lt;p&gt;Consider this list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;languages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rust&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;JavaScript&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rust&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can remove repeated values by converting it into a set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;unique_languages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unique_languages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The set keeps only one occurrence of each language.&lt;/p&gt;

&lt;p&gt;Sets are useful when you need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove duplicate values.&lt;/li&gt;
&lt;li&gt;Check whether a value is present.&lt;/li&gt;
&lt;li&gt;Compare groups of elements.&lt;/li&gt;
&lt;li&gt;Work with unique categories or identifiers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Unlike lists, sets do not support indexes or slicing.&lt;/p&gt;

&lt;h2&gt;
  
  
  An important detail
&lt;/h2&gt;

&lt;p&gt;Empty braces create an empty dictionary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;empty_dictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create an empty set, use &lt;code&gt;set()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;empty_set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a common source of confusion for Python beginners.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which structure should you choose?
&lt;/h2&gt;

&lt;p&gt;Use a &lt;strong&gt;list&lt;/strong&gt; when position and order are important.&lt;/p&gt;

&lt;p&gt;Use a &lt;strong&gt;dictionary&lt;/strong&gt; when every value should have a descriptive name.&lt;/p&gt;

&lt;p&gt;Use a &lt;strong&gt;set&lt;/strong&gt; when you need unique values and repetitions do not matter.&lt;/p&gt;

&lt;p&gt;Understanding this distinction makes programs easier to read, maintain, and extend.&lt;/p&gt;

&lt;p&gt;The original Spanish guide includes a step-by-step explanation with additional examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/diccionarios-y-conjuntos-datos-con-nombre-y-sin-duplicados/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/diccionarios-y-conjuntos-datos-con-nombre-y-sin-duplicados/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What was more confusing when you first learned Python: dictionaries or sets?&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python Lists and Tuples for Beginners: Organize Data Step by Step</title>
      <dc:creator>Tu codigo cotidiano</dc:creator>
      <pubDate>Thu, 16 Jul 2026 11:46:35 +0000</pubDate>
      <link>https://dev.to/tu_codigocotidiano_f173d/python-lists-and-tuples-for-beginners-organize-data-step-by-step-1mid</link>
      <guid>https://dev.to/tu_codigocotidiano_f173d/python-lists-and-tuples-for-beginners-organize-data-step-by-step-1mid</guid>
      <description>&lt;p&gt;When you start learning Python, storing information in individual variables feels natural:&lt;/p&gt;

&lt;p&gt;student_1 = "Ana"&lt;br&gt;
student_2 = "Luis"&lt;br&gt;
student_3 = "Marta"&lt;/p&gt;

&lt;p&gt;However, this approach becomes difficult to maintain as the amount of information grows.&lt;/p&gt;

&lt;p&gt;Python lists allow us to group related values inside a single ordered collection:&lt;/p&gt;

&lt;p&gt;students = ["Ana", "Luis", "Marta"]&lt;/p&gt;

&lt;p&gt;Now we can access each element using its index:&lt;/p&gt;

&lt;p&gt;print(students[0])   # Ana&lt;br&gt;
print(students[-1])  # Marta&lt;/p&gt;

&lt;p&gt;Because lists are mutable, their elements can be updated after creation:&lt;/p&gt;

&lt;p&gt;students[1] = "Carlos"&lt;/p&gt;

&lt;p&gt;We can also add new information using append() or insert():&lt;/p&gt;

&lt;p&gt;students.append("Laura")&lt;br&gt;
students.insert(1, "Daniel")&lt;/p&gt;

&lt;p&gt;To remove elements, Python provides methods such as remove() and pop():&lt;/p&gt;

&lt;p&gt;students.remove("Ana")&lt;br&gt;
removed_student = students.pop(1)&lt;/p&gt;

&lt;p&gt;Lists can also be inspected without modifying them:&lt;/p&gt;

&lt;p&gt;print(len(students))&lt;br&gt;
print("Laura" in students)&lt;br&gt;
print("Pedro" not in students)&lt;/p&gt;

&lt;p&gt;Another useful operation is slicing, which lets us obtain part of a list:&lt;/p&gt;

&lt;p&gt;numbers = [10, 20, 30, 40, 50]&lt;/p&gt;

&lt;p&gt;print(numbers[1:4])&lt;br&gt;
print(numbers[:3])&lt;br&gt;
print(numbers[3:])&lt;/p&gt;

&lt;p&gt;Lists are ideal when the information may change. Tuples, on the other hand, are useful when the values should remain stable.&lt;/p&gt;

&lt;p&gt;Understanding both structures is an essential step toward building cleaner programs, processing collections of data, and working with loops, functions, APIs, and databases.&lt;/p&gt;

&lt;p&gt;I created a practical, beginner-friendly guide explaining these concepts step by step, with examples in Spanish.&lt;/p&gt;

&lt;p&gt;📖 Read the complete guide:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tucodigocotidiano.yarumaltech.com/leer_guias/listas-y-tuplas-organiza-informacion-en-orden/" rel="noopener noreferrer"&gt;https://tucodigocotidiano.yarumaltech.com/leer_guias/listas-y-tuplas-organiza-informacion-en-orden/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What was the first real project where you needed to use a Python list?&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
