{ "cells": [ { "cell_type": "markdown", "id": "72cc2b3d-f21a-40df-9dfd-00a755d850c6", "metadata": { "tags": [] }, "source": [ "Impresión con formato usando f-strings\n", "===\n", "\n", "* Duración de la lección: 3:16 min " ] }, { "cell_type": "code", "execution_count": 1, "id": "f31d2b02-4787-4a82-9883-6e456d59595c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The value of pi is approximately 3.142.\n" ] } ], "source": [ "import math\n", "\n", "print(f\"The value of pi is approximately {math.pi:.3f}.\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "18501a49-41f4-4876-b998-8605b7a4a857", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sjoerd ==> 4127\n", "Jack ==> 4098\n", "Dcab ==> 7678\n" ] } ], "source": [ "table = {\"Sjoerd\": 4127, \"Jack\": 4098, \"Dcab\": 7678}\n", "for name, phone in table.items():\n", " print(f\"{name:10} ==> {phone:10d}\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "d776d4ca-09fb-4254-958d-ac74ac69dbc4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My hovercraft is full of eels.\n" ] } ], "source": [ "animals = \"eels\"\n", "\n", "print(f\"My hovercraft is full of {animals}.\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "39ebc00c-db26-4b77-bc30-c9214deb969f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My hovercraft is full of 'eels'.\n" ] } ], "source": [ "#\n", "# !a aplica ascii()\n", "#\n", "print(f\"My hovercraft is full of {animals!a}.\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "f8dd38a4-8b57-44ab-9973-b94f2ab2cd58", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My hovercraft is full of 'eels'.\n" ] } ], "source": [ "#\n", "# !r aplica la función repr()\n", "#\n", "print(f\"My hovercraft is full of {animals!r}.\")" ] } ], "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.6.9" } }, "nbformat": 4, "nbformat_minor": 5 }