{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "id": "40428e89", "metadata": { "id": "40428e89" }, "source": [ "# Operadores de comparación" ] }, { "cell_type": "markdown", "id": "5d0cfcb3", "metadata": { "id": "5d0cfcb3" }, "source": [ "- \\>\n", "- \\<\n", "- \\>=\n", "- \\<=\n", "- \\==     igual\n", "- \\!=      distinto\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "83d7bca8", "metadata": { "id": "83d7bca8", "outputId": "2b12c2f3-44fb-4b7a-9041-47be615a8320", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 1 } ], "source": [ "2 < 5" ] }, { "cell_type": "code", "execution_count": 2, "id": "a0d95a1d", "metadata": { "id": "a0d95a1d", "outputId": "e16a18a6-ae01-48e1-a005-2284c9db9168", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": {}, "execution_count": 2 } ], "source": [ "\"Ana\" > \"Jose\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "e35a23eb", "metadata": { "id": "e35a23eb", "outputId": "7c8f0af7-9da7-415f-eac9-1aedce18507f", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 3 } ], "source": [ "x = 3\n", "y = 4\n", "x**2 + y**2 >= 0" ] }, { "cell_type": "code", "execution_count": 4, "id": "9baaf80c", "metadata": { "id": "9baaf80c", "outputId": "3cf2e2ad-0333-4042-f1ae-a107369d5ca3", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 4 } ], "source": [ "2 == 8/4" ] }, { "cell_type": "code", "execution_count": 5, "id": "1dde0224", "metadata": { "id": "1dde0224", "outputId": "56a1d3ae-796f-4a23-d4e6-b886110bd5d6", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 5 } ], "source": [ "\"Alex\" != \"alex\"" ] }, { "cell_type": "markdown", "id": "c27dc84e", "metadata": { "id": "c27dc84e" }, "source": [ "## Comparando por rangos\n", "Las dos siguientes formas de comparar son completamente equivalentes." ] }, { "cell_type": "code", "execution_count": 6, "id": "bf630708", "metadata": { "id": "bf630708", "outputId": "acf537b2-4409-4b68-e52b-c838c03a2e7d", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 6 } ], "source": [ "x = 5\n", "0 < x and x < 10 # True" ] }, { "cell_type": "code", "execution_count": 7, "id": "547ffbe3", "metadata": { "id": "547ffbe3", "outputId": "e631bf2a-0f62-4787-b0d7-93b20a906f4c", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": {}, "execution_count": 7 } ], "source": [ "0 < x < 10 # True" ] }, { "cell_type": "markdown", "id": "3e98265b", "metadata": { "id": "3e98265b" }, "source": [ "## Condición lógica en un condicional" ] }, { "cell_type": "code", "execution_count": 8, "id": "e3b3f368", "metadata": { "id": "e3b3f368", "outputId": "4db90447-8bef-4e5d-f0b7-e02f473eed50", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "No son iguales\n" ] } ], "source": [ "a = 7\n", "b = 9\n", "\n", "if a == b:\n", " print(\"Si son iguales\")\n", "\n", "if a != b:\n", " print(\"No son iguales\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" }, "colab": { "name": "0280_operaciones_de_comparacion.ipynb", "provenance": [], "include_colab_link": true } }, "nbformat": 4, "nbformat_minor": 5 }