{ "cells": [ { "cell_type": "markdown", "id": "843a42a8-35a1-4061-8d0b-2cbd7442ef4f", "metadata": {}, "source": [ "# Woche 01" ] }, { "cell_type": "code", "execution_count": 19, "id": "9cc0f19c-2374-4cc4-ae0e-a3f4515442cd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# assign 4 to the variable x\n", "x = 4\n", "x * 2" ] }, { "cell_type": "code", "execution_count": 16, "id": "3d0af26e-3aa0-49f8-b7fd-988b72d32d6a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 1 # x is an integer\n", "type( x )" ] }, { "cell_type": "code", "execution_count": 20, "id": "c976e529-1fd1-43bc-881f-c813bc528cd0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'hellohello'" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 'hello' # now x is a string\n", "x * 2" ] }, { "cell_type": "code", "execution_count": 18, "id": "fcffa208-d671-4937-9a13-08aa35216682", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = [1, 2, 3] # now x is a list\n", "type ( x )\n" ] }, { "cell_type": "markdown", "id": "e25c8f9e-ad27-4fd6-b78d-1e6337455c4a", "metadata": {}, "source": [ "## Exkurs: Datentypen nach Operatoren" ] }, { "cell_type": "code", "execution_count": 21, "id": "98a85bd2-3c19-426c-b17d-7a84b29195dd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.3333333333333335" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "7 / 3" ] }, { "cell_type": "code", "execution_count": 22, "id": "ac3cd4f2-77d1-4ef8-81b2-841d9dd736cf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "9/3" ] }, { "cell_type": "code", "execution_count": 25, "id": "fed8277a-7e0b-44f3-970c-5e21d6be6c3d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type ( 7 % 3 )" ] }, { "cell_type": "code", "execution_count": 26, "id": "0a2d3f2f-d8f7-4da9-8c22-8dcee01c087e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type ( 7 // 3 )" ] }, { "cell_type": "markdown", "id": "bee1ba62-8877-4191-944c-0dd77a317284", "metadata": {}, "source": [ "## Pointer" ] }, { "cell_type": "code", "execution_count": 27, "id": "b10d5f0a-ba22-4e00-b3ea-7381656dde3d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3, 3)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 3\n", "y = x\n", "\n", "x , y" ] }, { "cell_type": "code", "execution_count": 28, "id": "48199b0a-fad6-41e3-9fc6-bd87c22be4ce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "33" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 33\n", "x" ] }, { "cell_type": "code", "execution_count": 29, "id": "e3388fb3-0097-4f24-a9a8-723058eb963f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y" ] }, { "cell_type": "code", "execution_count": 30, "id": "249d5da6-1bb6-4825-aa66-0fabd7197bdd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([1, 2, 3], [1, 2, 3])" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = [1, 2, 3]\n", "q = p\n", "\n", "p, q" ] }, { "cell_type": "code", "execution_count": 31, "id": "36cd97db-8af9-4a45-8513-ee1635d6d30d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99]" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.append( 99 )\n", "p" ] }, { "cell_type": "code", "execution_count": 32, "id": "c2bd91f1-4152-429a-93eb-982ee4a0e33f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q" ] }, { "cell_type": "code", "execution_count": 33, "id": "150670a1-abad-461c-8717-840c07d5a017", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99, 1001, 1002]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.extend( [ 1001, 1002 ] )\n", "p" ] }, { "cell_type": "code", "execution_count": 34, "id": "b23f09c8-2ab6-4729-828e-a30a54358944", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99, 1001, 1002]" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q" ] }, { "cell_type": "code", "execution_count": 35, "id": "af05c559-82e7-4132-b3ce-9c26b172c0cd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99, 1001, 1002, 2001, 2002, 2003]" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = p + [ 2001, 2002, 2003 ]\n", "p" ] }, { "cell_type": "code", "execution_count": 36, "id": "875aaf34-9c07-4a78-8d15-d5d2b4f54d9e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 99, 1001, 1002]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q" ] }, { "cell_type": "code", "execution_count": 42, "id": "3fa8ffdb-81f2-43ea-a602-4a70327ff837", "metadata": {}, "outputs": [], "source": [ "l = [ 1, 2, 3]\n", "m = [ 100, 102, 102 ]" ] }, { "cell_type": "code", "execution_count": 4, "id": "75727bdd-4e50-4895-a2c8-b0f0e74b7749", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e_gleich_e = 1 == 1\n", "e_gleich_e" ] }, { "cell_type": "code", "execution_count": 5, "id": "b5eccd8b-3e09-4780-b991-6c25a41916a4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "bool" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type ( e_gleich_e )" ] }, { "cell_type": "code", "execution_count": 6, "id": "7ba2bdeb-058e-40f5-affb-b4fe3bd52c15", "metadata": {}, "outputs": [], "source": [ "x = None\n", "x" ] }, { "cell_type": "code", "execution_count": 7, "id": "7d9563bb-cdd6-4a5d-b7b1-b7b01275289a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "None\n" ] } ], "source": [ "print( x )" ] }, { "cell_type": "code", "execution_count": 8, "id": "d0bf7769-8a70-4de3-b341-395441164514", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "NoneType" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type( x )" ] }, { "cell_type": "markdown", "id": "618a2483-a0bd-4976-8883-983c2793f1f2", "metadata": {}, "source": [ "# Listen und Strings" ] }, { "cell_type": "markdown", "id": "458f5235-3456-4864-b4aa-b7ec8e560e01", "metadata": {}, "source": [ "## Slicing" ] }, { "cell_type": "code", "execution_count": 10, "id": "7ce46afe-587d-4cc9-82bf-906de38f2ff0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hallo!'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h = \"Hallo!\"\n", "h" ] }, { "cell_type": "code", "execution_count": null, "id": "8ade7ebe-16db-4689-a08e-3d25458548fd", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "700d64f7-3e7f-4458-bcd0-0d4023494c9a", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "88193c58-1854-4ac4-aacb-bacd454b96c3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "4347360d-ad77-4696-b83c-01a2c7e7d0fe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "fcca20bd-27ba-4c63-9641-55c880939b40", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 11, "id": "1ae57102-1734-4ff3-8f6d-e8cdae216121", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'a', 'l', 'l', 'o', '!']" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = [ 'H', 'a', 'l', 'l', 'o', '!' ] \n", "l" ] }, { "cell_type": "code", "execution_count": 38, "id": "2bffd530-9503-4a6b-b0fc-0110616f9581", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'a', 'l', 'l', 'o', '!']" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list( h )\n" ] }, { "cell_type": "code", "execution_count": 15, "id": "693bfeb1-2379-447d-800e-dcc7dc5d9860", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'H'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h[0]" ] }, { "cell_type": "code", "execution_count": 16, "id": "e05a208c-a6ff-4d03-8b66-133b42897d58", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'H'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[0]" ] }, { "cell_type": "code", "execution_count": 17, "id": "c9d74b9b-af58-4541-a734-727057c70924", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hal'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h[ 0:3 ]" ] }, { "cell_type": "code", "execution_count": 18, "id": "1811b53c-e61a-4809-9ec5-053f67811cdb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'a', 'l']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[ 0:3 ]" ] }, { "cell_type": "code", "execution_count": 25, "id": "8db56458-1d6c-4be7-b2a4-79bf56977bec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type( h[:] )" ] }, { "cell_type": "code", "execution_count": 26, "id": "52cc067f-6ca7-4d91-94b6-f6802b3f6bfc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type( l[:] )" ] }, { "cell_type": "code", "execution_count": 32, "id": "bfb48f83-fea2-4539-988d-f0b940d67859", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'!ollaH'" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h[::-1]" ] }, { "cell_type": "code", "execution_count": 35, "id": "0cad29c2-daa6-463e-bc3a-fb1fc8b14b81", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'a', 'l', 'l']" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[ :-2 ]" ] }, { "cell_type": "code", "execution_count": 37, "id": "b6c5a3bd-d3bb-4c7a-82a1-45138ba58e57", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'a', 'l', 'l', 'o', '!']" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list( h )" ] }, { "cell_type": "code", "execution_count": 42, "id": "40c56955-12ee-45a3-91fa-9fc7a87f3a9e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\n" ] } ], "source": [ "kleinbuchstaben = \"abcdefghijklmnopqrstuvwxyz\"\n", "print( list( kleinbuchstaben ) )" ] }, { "cell_type": "code", "execution_count": 45, "id": "1d8fd94b-922c-408a-af47-e5b5761d5185", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"!\" in kleinbuchstaben" ] }, { "cell_type": "code", "execution_count": 47, "id": "cb42d793-043b-4e12-b4dd-07d9b3d33bb5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"xy\" in \"abcxyz\"" ] }, { "cell_type": "code", "execution_count": 49, "id": "e9e3a5a8-766b-4c05-a3e4-7292d43986e8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('Hallo!', str)" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h, type( h )" ] }, { "cell_type": "code", "execution_count": 53, "id": "003154e6-e6f4-4c99-ad20-892294f63bb8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'HALLO!'" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h.upper()" ] }, { "cell_type": "code", "execution_count": 54, "id": "3fabfdf5-8065-415a-a6ce-2c25c70b75c1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'HALLO WELT!'" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"Hallo Welt!\".upper()" ] }, { "cell_type": "code", "execution_count": 86, "id": "ae95e403-cad0-4c4d-a78c-85a1a6951f65", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "72\n", "72\n", "63\n" ] } ], "source": [ "satz = \" Die Methode stip() entfernt linke und rechte Leerzeichen. \"\n", "print( len(satz) )\n", "satz.strip() \n", "print( len(satz) )\n", "satz2 = satz.strip()\n", "print( len(satz2) )" ] }, { "cell_type": "code", "execution_count": 89, "id": "7dfc24ec-3f09-4a19-9376-ae7a361cb34a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'split() nimmt einen String und teilt ihn am Split-Zeichen auf.'" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "satz = \"split() nimmt einen String und teilt ihn am Split-Zeichen auf.\"\n", "satz" ] }, { "cell_type": "code", "execution_count": 90, "id": "17c369c6-0da7-48b4-8804-9c11ee018794", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['split()', 'nimmt', 'einen', 'String', 'und', 'teilt', 'ihn', 'am', 'Split-Zeichen', 'auf.']\n" ] } ], "source": [ "satz_lvs = satz.split() # lvs ... Liste von Strings\n", "print( satz_lvs )" ] }, { "cell_type": "code", "execution_count": 91, "id": "4eb37bba-0174-4edc-964c-03d6da743e96", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'SPLIT()--NIMMT--EINEN--STRING--UND--TEILT--IHN--AM--SPLIT-ZEICHEN--AUF.'" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"--\".join( satz_lvs ).upper()" ] }, { "cell_type": "code", "execution_count": null, "id": "8a4d7d2e-452b-4386-b6f6-8993c294e63d", "metadata": {}, "outputs": [], "source": [] } ], "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }