{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "\n", "# Hi Dan\n", "1. Thanks for fixing the last issue so quickly\n", "1. This library is really cool\n", "1. I'll probably start using it for work soon\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import Markdown, display\n", "\n", "display(Markdown('''\n", "# Hi Dan\n", "1. Thanks for fixing the last issue so quickly\n", "1. This library is really cool\n", "1. I'll probably start using it for work soon\n", "'''))" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "
User: mynbiqpmzj
Password: plsgqejeydtzirwztejd
\n", " " ], "text/plain": [ "<__main__.RandomUser at 0x105050588>" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from random import choice, seed\n", "from string import ascii_lowercase\n", "\n", "seed(0)\n", "\n", "def _random_str(length: int):\n", " return ''.join(choice(ascii_lowercase) for _ in range(length))\n", "\n", "class RandomUser:\n", " def __init__(self):\n", " self.user = _random_str(10)\n", " self.password = _random_str(20)\n", " \n", " def _repr_html_(self):\n", " return f'''\n", " \n", " \n", " \n", "
User: {self.user}
Password: {self.password}
\n", " '''\n", " \n", "RandomUser()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/json": { "hello": "world" }, "text/plain": [ "{'hello': 'world'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import json\n", "\n", "class DisplayDict(dict):\n", " def _repr_json_(self):\n", " return self\n", " \n", "DisplayDict({'hello': 'world'})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }