LUNAR
π
Dashboard
Browse
SW02_Notes
JUPYTER
View Source
{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notes\n", "## Link to a picture\n", "### From internet\n", "```python\n", "\"\"\n", "```\n", "### From local\n", "```python\n", "\"\"\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Variables\n", "\n", "Use lower letters for variables and capital letters for constant.\n", "\n", "### Conversion\n", "```python\n", "int(x) Always rounds down\n", "```" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "43 43.04668421400553 palle giganti False\n" ] } ], "source": [ "x = 1.45678**10\n", "y = \"palle giganti\"\n", "print(int(x),float(x),str(y),bool(x==y))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Module (remainer)\n", "```python\n", "x%y\n", "```\n", "With \"%\", we devide as many time as we can the numerator by the divisor, getting, as a result, the remainer value" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "100%5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Print values\n", "- **\\\\** = spacer (to have \\\\, just write \"\\\\\\\\\");\n", "- **\\t** = tap, big space between two elements;\n", "- **\\n** = new line, the next value will be printed in the next line;\n", "- **-r** strings = raw string, print(r\"text with special characters\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### More lines\n", "```python\n", "print(\n", " \"\"\"\n", "-------------------------\n", " first line\n", "-------------------------\n", " second line\n", "\"\"\")\n", "\n", "```" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "π₯hellπ₯\n" ] } ], "source": [ "def func():\n", " \"\"\"\n", " fire emoji\n", " \"\"\"\n", " x=str(\"π₯\")\n", " pass\n", "\n", "print(x+\n", "\"\"\"\n", " hello\n", " world\n", "\"\"\"[5:9]+x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "<img src=\"https://w7.pngwing.com/pngs/389/55/png-transparent-demon-devil-islamic-art-hell-demon-poster-fictional-character-religion.png\" alt=\"Demon Image\" width=\"250\" height=\"250\">\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Multiple outputs with print()" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10\t20\n", "11110\n" ] } ], "source": [ "x=10\n", "y=20\n", "z=30\n", "# print(x,\"\\t\",y,\"\\t\",z)\n", "# print(x,\"\\n\",y,\"\\n\",z)\n", "print(f\"{x}\\t{y}\\n{z:b}\")" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3**2=9 \t 3:2=1.5\n" ] } ], "source": [ "x=3\n", "print(f\"3**2={x**2} \\t 3:2={x/2}\")" ] } ], "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.12.6" } }, "nbformat": 4, "nbformat_minor": 2 }