{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notitzen" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "temp = 30.2\n", "temp_room_1 = 30.5\n" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sdfsdfsd 00030\n" ] } ], "source": [ "print(f\"sdfsdfsd {int(temp):05}\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "F\n", "a\n", "b\n", "i\n", "a\n", "n\n" ] } ], "source": [ "for letter in \"Fabian\":\n", " print(letter)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 2, 4, 6, 8]" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(0,10,2))\n" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "6\n" ] } ], "source": [ "for i in range(10):\n", " \n", " if i == 5:\n", " continue\n", " if i > 6:\n", " break\n", "\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "i" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "4\n", "6\n", "8\n", "10\n", "12\n", "14\n", "16\n", "18\n", "The sum is 90\n" ] } ], "source": [ "sum = 0\n", "for i in range(1,20):\n", " if i%2 == 0:\n", " print(i)\n", " sum += i\n", "\n", "print(f\"The sum is {sum}\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def print_name(age:int, name:str = \"Fabian\")->None:\n", " \"\"\" \n", " Prints the name of a person\n", "\n", " Parameters:\n", " name (str): Name of a person\n", " age (int): Age of a person\n", "\n", " Returns:\n", " None\n", " \"\"\"\n", " print(f\"Hello {name}, i am {age} years old\")" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello Fabian, i am 25 years old\n" ] } ], "source": [ "print_name(25)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello Julia\n" ] } ], "source": [ "print_name(name=\"Julia\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(4, 5)\n", "\n" ] } ], "source": [ "def add(x,y,*xargs):\n", " print(xargs)\n", " print(type(xargs))\n", "\n", "add(2,3,4,5)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'z': 10, 'z1': 'asdsa', 'z2': 'test'}\n", "\n" ] } ], "source": [ "def add_2(x,y,**kwargs):\n", " print(kwargs)\n", " print(type(kwargs))\n", "\n", "add_2(x = 1,y = 4, z = 10, z1 = \"asdsa\", z2 = \"test\")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1,2) in (1,2,3,4,(1,2))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 in (1,2,3,4,(1,2)) and 2 in (1,2,3,4,(1,2))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "x,y, *z, z2 = (1,2,3,5)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 2)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x,y" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z2" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[3]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 5, 4]" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = [1,2,3]\n", "x.extend([5,4])\n", "x" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, [5, 4]]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = [1,2,3]\n", "x.append([5,4])\n", "x" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[5, 4], 3, 2, 1]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x.reverse()\n", "x" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, [5, 4]]" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x[::-1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def list_add(item, mylist:list=None)->list:\n", " if mylist is None:\n", " mylist = []\n", " mylist.append(item)\n", " return mylist" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "set" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "empty_set = set()\n", "type(empty_set)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Fabian'" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict = {}\n", "\n", "my_dict[\"Name\"] = \"Fabian\"\n", "my_dict[\"Name\"]" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Name': 'Robert'}" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict[\"Name\"] = \"Robert\"\n", "my_dict" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Name': 'Robert', 'Age': 4}" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict[\"Age\"] = 4\n", "my_dict" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict_2 = {}\n", "my_dict_2[\"Person1\"] = {\"Name\": \"Robert\", \"Age\": 5}\n", "my_dict_2[\"Person2\"] = {\"Name\": \"Fabian\", \"Age\": 5}\n", "my_dict_2[\"Person1\"][\"Age\"]" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Name Robert\n", "Age 4\n" ] } ], "source": [ "for x,y in my_dict.items():\n", " print(x,y)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "'Test3'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", "Input \u001b[1;32mIn [53]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmy_dict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mTest3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n", "\u001b[1;31mKeyError\u001b[0m: 'Test3'" ] } ], "source": [ "my_dict[\"Test3\"]" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Name': 'Robert', 'Age': 4, 'Test': 4, 'Test2': None, 'Test3': None}" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "my_dict.setdefault(\"Test3\")" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Person1': {'Name': 'Robert', 'Age': 5},\n", " 'Person2': {'Name': 'Fabian', 'Age': 5}}" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_dict_2" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.9.12" } }, "nbformat": 4, "nbformat_minor": 2 }