{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "id": "38653a89", "metadata": { "id": "38653a89" }, "source": [ "# Nombres de variables" ] }, { "cell_type": "markdown", "id": "c3f43f13", "metadata": { "id": "c3f43f13" }, "source": [ "Una variable es un espacio en memoria capaz de contener un dato. \n", "Las variables en Python son **case-sensitive**, se diferencia entre mayúsculas y minúsculas.\n", "\n", "Dos estilos:\n", "- [camelCase](https://www.google.com/search?q=camelCase)\n", "- [snake_case](https://www.google.com/search?q=snake_case)" ] }, { "cell_type": "code", "execution_count": null, "id": "3450565f", "metadata": { "id": "3450565f" }, "outputs": [], "source": [ "mi_nombre = \"Felipe\" # se recomienda empezar con minúscula\n", "_ciudad = \"Buenos Aires\"\n", "edad4 = 23" ] }, { "cell_type": "code", "execution_count": null, "id": "db39c43b", "metadata": { "id": "db39c43b" }, "outputs": [], "source": [ "#mi-nombre = \"Ana\" # error, no acepta guion ni otros símbolos" ] }, { "cell_type": "code", "execution_count": null, "id": "431ba35c", "metadata": { "id": "431ba35c" }, "outputs": [], "source": [ "#mi nombre = \"Ana\" # error, no puede contener espacios" ] }, { "cell_type": "code", "execution_count": null, "id": "1c0a6d5b", "metadata": { "id": "1c0a6d5b" }, "outputs": [], "source": [ "#4edad = 15 # error, no puede empezar por número" ] }, { "cell_type": "code", "execution_count": null, "id": "b8231eab", "metadata": { "id": "b8231eab" }, "outputs": [], "source": [ "#$edad = 30 # error, no puede empezar por símbolo" ] }, { "cell_type": "code", "execution_count": null, "id": "9e70faff", "metadata": { "id": "9e70faff", "outputId": "aedbb280-4af9-4537-f6fc-9c74d6f120e0", "colab": { "base_uri": "https://localhost:8080/", "height": 35 } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'Juan Ruiz'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 6 } ], "source": [ "nombreApellidos = \"Juan Ruiz\" # lower camel style\n", "NombreApellidos = \"Pablo Díez\" # upper camel style\n", "nombre_del_padre = \"Juan\" # sanke case\n", "nombreApellidos" ] }, { "cell_type": "code", "execution_count": null, "id": "560ce564", "metadata": { "id": "560ce564", "outputId": "1894e35e-c104-44f2-c52e-42b349022605", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": {}, "execution_count": 7 } ], "source": [ "nombreApellidos == NombreApellidos # False, case sensitive" ] }, { "cell_type": "markdown", "id": "65a29922", "metadata": { "id": "65a29922" }, "source": [ "# Palabras reservadas\n", "* Python Keywords\n", "* Existen ciertos nombres reservamos que no se pueden usar como nombres de variables." ] }, { "cell_type": "code", "source": [ "import keyword # aquí importamos una librería que esta llena de funciones\n", "print(keyword.kwlist) # una de esas funciones es kwlist que listas las keywords" ], "metadata": { "id": "OpkhiGO9XHkq", "outputId": "5345d065-0d2b-4091-cddb-faa213a32fa6", "colab": { "base_uri": "https://localhost:8080/" } }, "id": "OpkhiGO9XHkq", "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']\n" ] } ] }, { "cell_type": "code", "execution_count": null, "id": "4341e10b", "metadata": { "id": "4341e10b" }, "outputs": [], "source": [ "# Ejemplo que da error\n", "#import = 15" ] }, { "cell_type": "code", "execution_count": null, "id": "9cfcb06b", "metadata": { "id": "9cfcb06b", "outputId": "9d65df1e-c07f-4944-816b-362f63b9a4f4", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "15" ] }, "metadata": {}, "execution_count": 9 } ], "source": [ "# import es una palabra reservada del lenguaje\n", "# Mejor usar myimport o my_import\n", "myimport = 15\n", "myimport" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11" }, "colab": { "name": "0070_nombres_de_variables.ipynb", "provenance": [], "include_colab_link": true } }, "nbformat": 4, "nbformat_minor": 5 }