{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python Basics (2023-11-29 - 2023-12-01)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "blah blah " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hello world\n" ] } ], "source": [ "print('hello world')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "a = 42" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the answer\n" ] } ], "source": [ "if a == 42:\n", " print('the answer')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## BlahBlah" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "del a" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "a = 42" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "42\n" ] } ], "source": [ "print(a)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(a)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(type(a))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "i = 100" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0x64'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(i)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b1100100'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(i)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "i = 300" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b100101100'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(i)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "i = 1" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b1'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(i)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b0'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(0)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "i = 2**64 - 1" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0b1111111111111111111111111111111111111111111111111111111111111111'" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bin(i)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "66" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(bin(i))" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "i += 1" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "18446744073709551616" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "i" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "67" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(bin(i))" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**10000" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(i)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "type_of_i = type(i)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "print(type_of_i)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hello world\n" ] } ], "source": [ "msg = 'hello world'\n", "print(msg)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(msg)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "builtin_function_or_method" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(print)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(i)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "i = ['abc', 1, 666.42]" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(i)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Syntax" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "answer = 666" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "schade\n" ] } ], "source": [ "if answer == 42:\n", " print('yay')\n", " print('das ist mal eine antwort')\n", "else:\n", " print('schade')" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "das ist mal eine antwort\n" ] } ], "source": [ "if answer == 42:\n", " print('yay')\n", "print('das ist mal eine antwort')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Variables" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "msg = 'hello world'" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hello world\n" ] } ], "source": [ "print(msg)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hello worldhello world\n" ] } ], "source": [ "print(msg*2)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n" ] } ], "source": [ "i = 0\n", "while i < 7:\n", " print(i)\n", " i += 1" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "a = 42" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(a)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "a = 1.5" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "float" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(a)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "a = [42, 'blah']" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(a)" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "a = 42" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "b = a" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "140572055569936" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id(a)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "140572055569936" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id(b)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "a = 7" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "c = b" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "b += 1" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "43" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "l1 = [1, 'two']" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "l2 = l1" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id(l1) == id(l2)" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l1 is l2" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "l1.append(3.0)" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0]" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l1" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0]" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l2" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [], "source": [ "l3 = [1, 'two']" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l1 == l3" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l1 is l3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## DataTypes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is Equality? (``==``)" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "a = '666'" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [], "source": [ "b = 666" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a == b" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(a) == b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Integers" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.5" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3/2" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3//2" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "import math" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.0" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.sqrt(4)" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(4.500001)" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on built-in function round in module builtins:\n", "\n", "round(number, ndigits=None)\n", " Round a number to a given precision in decimal digits.\n", " \n", " The return value is an integer if ndigits is omitted or None. Otherwise\n", " the return value has the same type as the number. ndigits may be negative.\n", "\n" ] } ], "source": [ "help(round)" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5.0" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(4.65, 0)" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "6/3 == 100/50" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eh gleich\n" ] } ], "source": [ "if abs(6/3 - 100/50) < 0.001:\n", " print('eh gleich')" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(3.499999999999999999999999)" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(4.4999)" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [], "source": [ "def my_round(f):\n", " import math\n", " cf = math.ceil(f)\n", " diff_to_next = cf - f\n", " if diff_to_next <0.5001:\n", " return cf\n", " else:\n", " return math.floor(f)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_round(3.5)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_round(3.1)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_round(3.6)" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_round(3.500000001)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Datatype Conversions" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [], "source": [ "str_i = \"666\"" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "str" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(str_i)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [], "source": [ "int_i = int(str_i)" ] }, { "cell_type": "code", "execution_count": 93, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(int_i)" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int_i == str_i" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'666'" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "str(int_i)" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [], "source": [ "float_i = float(int_i)" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "666.0" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float_i" ] }, { "cell_type": "code", "execution_count": 98, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "666.0" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float('666')" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " could not convert string to float: 'abc'\n" ] } ], "source": [ "try:\n", " float('abc')\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " invalid literal for int() with base 10: '666.42'\n" ] } ], "source": [ "try:\n", " int('666.42')\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " invalid literal for int() with base 10: 'abc'\n" ] } ], "source": [ "try:\n", " int('abc')\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 102, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2748" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int('abc', 16)" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(666)" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(0)" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool('666')" ] }, { "cell_type": "code", "execution_count": 106, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eh\n" ] } ], "source": [ "i = 666\n", "if i:\n", " print('eh')" ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "nix\n" ] } ], "source": [ "i = 0\n", "if not i:\n", " print('nix')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### List (*mutable*)" ] }, { "cell_type": "code", "execution_count": 108, "metadata": {}, "outputs": [], "source": [ "l = [1, 'two', 3.0]" ] }, { "cell_type": "code", "execution_count": 109, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(l)" ] }, { "cell_type": "code", "execution_count": 110, "metadata": {}, "outputs": [], "source": [ "l.append(4)" ] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0, 4]" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 112, "metadata": {}, "outputs": [], "source": [ "nocheineliste = [5, 6, 7]" ] }, { "cell_type": "code", "execution_count": 113, "metadata": {}, "outputs": [], "source": [ "l += nocheineliste" ] }, { "cell_type": "code", "execution_count": 114, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0, 4, 5, 6, 7]" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 115, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0, 4, 5, 6, 7, 8, 9, 10]" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.extend([8, 9, 10])\n", "l" ] }, { "cell_type": "code", "execution_count": 116, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l[3]" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [], "source": [ "l.append([11, 12, 13])" ] }, { "cell_type": "code", "execution_count": 118, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 'two', 3.0, 4, 5, 6, 7, 8, 9, 10, [11, 12, 13]]" ] }, "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "11" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(l)" ] }, { "cell_type": "code", "execution_count": 120, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "666 in l" ] }, { "cell_type": "code", "execution_count": 121, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "12 in l" ] }, { "cell_type": "code", "execution_count": 122, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" } ], "source": [ "12 == [11, 12, 13]" ] }, { "cell_type": "code", "execution_count": 123, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "12 in l[-1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tuple (*immutable*)" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "140571746172800" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = (1, 'two', 3.0)\n", "id(t)" ] }, { "cell_type": "code", "execution_count": 125, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tuple" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(t)" ] }, { "cell_type": "code", "execution_count": 126, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 'tuple' object has no attribute 'append'\n" ] } ], "source": [ "try:\n", " t.append(4)\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 127, "metadata": {}, "outputs": [], "source": [ "t += (4, 5, 6)" ] }, { "cell_type": "code", "execution_count": 128, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "140571753417312" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id(t)" ] }, { "cell_type": "code", "execution_count": 129, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[3]" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [], "source": [ "t = (666)" ] }, { "cell_type": "code", "execution_count": 131, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "int" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(t)" ] }, { "cell_type": "code", "execution_count": 132, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2*3+4" ] }, { "cell_type": "code", "execution_count": 133, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "14" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2*(3+4)" ] }, { "cell_type": "code", "execution_count": 134, "metadata": {}, "outputs": [], "source": [ "t = (666,)" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tuple" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(t)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dictionary (*mutable*)" ] }, { "cell_type": "code", "execution_count": 136, "metadata": {}, "outputs": [], "source": [ "d = {\n", " 'one': 1,\n", " 'two': 2,\n", "}" ] }, { "cell_type": "code", "execution_count": 137, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d['one']" ] }, { "cell_type": "code", "execution_count": 138, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'one' in d" ] }, { "cell_type": "code", "execution_count": 139, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 'three'\n" ] } ], "source": [ "try:\n", " d['three']\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 140, "metadata": {}, "outputs": [], "source": [ "d['three'] = 3" ] }, { "cell_type": "code", "execution_count": 141, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 141, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d['three']" ] }, { "cell_type": "code", "execution_count": 142, "metadata": {}, "outputs": [], "source": [ "v = d.get('four')" ] }, { "cell_type": "code", "execution_count": 143, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "None\n" ] } ], "source": [ "print(v)" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.get('three')" ] }, { "cell_type": "code", "execution_count": 145, "metadata": {}, "outputs": [], "source": [ "del d['three']" ] }, { "cell_type": "code", "execution_count": 146, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'three' in d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set (*mutable*)" ] }, { "cell_type": "code", "execution_count": 147, "metadata": {}, "outputs": [], "source": [ "s = {1, 2, 3}" ] }, { "cell_type": "code", "execution_count": 148, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3 in s" ] }, { "cell_type": "code", "execution_count": 149, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "4 not in s" ] }, { "cell_type": "code", "execution_count": 150, "metadata": {}, "outputs": [], "source": [ "s.add(4)" ] }, { "cell_type": "code", "execution_count": 151, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 3, 4}" ] }, "execution_count": 151, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s" ] }, { "cell_type": "code", "execution_count": 152, "metadata": {}, "outputs": [], "source": [ "s.add(4)" ] }, { "cell_type": "code", "execution_count": 153, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 3, 4}" ] }, "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s" ] }, { "cell_type": "code", "execution_count": 154, "metadata": {}, "outputs": [], "source": [ "s.remove(1)" ] }, { "cell_type": "code", "execution_count": 155, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 155, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 in s" ] }, { "cell_type": "code", "execution_count": 156, "metadata": {}, "outputs": [], "source": [ "s1 = {1, 2, 3, 4}\n", "s2 = {3, 4, 5, 6}" ] }, { "cell_type": "code", "execution_count": 157, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 3, 4, 5, 6}" ] }, "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s1 | s2" ] }, { "cell_type": "code", "execution_count": 158, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{3, 4}" ] }, "execution_count": 158, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s1 & s2" ] }, { "cell_type": "code", "execution_count": 159, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 5, 6}" ] }, "execution_count": 159, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s1 ^ s2" ] }, { "cell_type": "code", "execution_count": 160, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 160, "metadata": {}, "output_type": "execute_result" } ], "source": [ "i = 42\n", "i.__hash__()" ] }, { "cell_type": "code", "execution_count": 161, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2282548071841868421" ] }, "execution_count": 161, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_s = 'abc'\n", "my_s.__hash__()" ] }, { "cell_type": "code", "execution_count": 162, "metadata": {}, "outputs": [], "source": [ "s.add('abc')" ] }, { "cell_type": "code", "execution_count": 163, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{2, 3, 4, 'abc'}" ] }, "execution_count": 163, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s" ] }, { "cell_type": "code", "execution_count": 164, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " unhashable type: 'list'\n" ] } ], "source": [ "try:\n", " s.add([1, 2, 3])\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 165, "metadata": {}, "outputs": [], "source": [ "s.add((1,2,3))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Boolean (*immutable*)" ] }, { "cell_type": "code", "execution_count": 166, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 166, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 < 2" ] }, { "cell_type": "code", "execution_count": 167, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 167, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 < 1" ] }, { "cell_type": "code", "execution_count": 168, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n" ] } ], "source": [ "i = 0\n", "while i < 7:\n", " print(i)\n", " i += 1" ] }, { "cell_type": "code", "execution_count": 169, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 169, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(42)" ] }, { "cell_type": "code", "execution_count": 170, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 170, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(0)" ] }, { "cell_type": "code", "execution_count": 171, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 171, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool('')" ] }, { "cell_type": "code", "execution_count": 172, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 172, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool('0')" ] }, { "cell_type": "code", "execution_count": 173, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 173, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(None)" ] }, { "cell_type": "code", "execution_count": 174, "metadata": {}, "outputs": [], "source": [ "a = 42" ] }, { "cell_type": "code", "execution_count": 175, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "yay\n" ] } ], "source": [ "if a == 42:\n", " print('yay')\n", "else:\n", " print('oioi')" ] }, { "cell_type": "code", "execution_count": 176, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 176, "metadata": {}, "output_type": "execute_result" } ], "source": [ "True and False" ] }, { "cell_type": "code", "execution_count": 177, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 177, "metadata": {}, "output_type": "execute_result" } ], "source": [ "True or False" ] }, { "cell_type": "code", "execution_count": 178, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 178, "metadata": {}, "output_type": "execute_result" } ], "source": [ "False or True" ] }, { "cell_type": "code", "execution_count": 179, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 179, "metadata": {}, "output_type": "execute_result" } ], "source": [ "True or False and print('boah')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ``while`` Loops" ] }, { "cell_type": "code", "execution_count": 180, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "ueberbleibsel 7\n" ] } ], "source": [ "i = 0\n", "while i < 7:\n", " print(i)\n", " i += 1\n", " \n", "print('ueberbleibsel', i)" ] }, { "cell_type": "code", "execution_count": 183, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5050\n" ] } ], "source": [ "my_sum = 0\n", "i = 0\n", "while i < 101:\n", " my_sum += i\n", " i += 1\n", "print(my_sum)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5050" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sum(range(101)) # pythonic" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import random" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "win\n" ] } ], "source": [ "n_tries = 5\n", "while n_tries != 0:\n", " n_tries -= 1\n", " eyes = random.randrange(1, 7)\n", " if eyes == 6:\n", " print('win')\n", " break\n", "else:\n", " print('lose')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ``for`` Loops" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "i = 0\n", "while i < 5:\n", " print(i)\n", " i += 1" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "for i in range(0, 5):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "2\n", "4\n" ] } ], "source": [ "for i in range(0, 5, 2):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n" ] } ], "source": [ "for i in range(2, 10):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "l = [0, 1, 2, 3, 4]\n", "for i in l:\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "s = {0, 1, 2, 3, 4}\n", "for i in s:\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "one\n", "two\n" ] } ], "source": [ "d = {'one': 1, 'two': 2}\n", "for elem in d:\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "one\n", "two\n" ] } ], "source": [ "d = {'one': 1, 'two': 2}\n", "for elem in d.keys():\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n" ] } ], "source": [ "for elem in d.values():\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('one', 1)\n", "('two', 2)\n" ] } ], "source": [ "for elem in d.items():\n", " print(elem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tuple Unpacking" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key: one value: 1\n", "key: two value: 2\n" ] } ], "source": [ "for elem in d.items():\n", " k = elem[0]\n", " v = elem[1]\n", " print('key:', k, 'value:', v)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key: one value: 1\n", "key: two value: 2\n" ] } ], "source": [ "for k, v in d.items():\n", " print('key:', k, 'value:', v)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "l = ['one', 2, 3.0]" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [], "source": [ "a, b, c = l" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "one 2 3.0\n" ] } ], "source": [ "print(a, b, c)" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [], "source": [ "a = 1\n", "b = 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Exchange values of a and b!" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "tmp = a\n", "a = b\n", "b = tmp" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 1\n" ] } ], "source": [ "print(a, b)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "a = 1\n", "b = 2" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "a, b = b, a" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2 1\n" ] } ], "source": [ "print(a, b)" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [], "source": [ "def f():\n", " return 42, 666" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "answer, doom = f()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(42, 666)" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "answer, doom" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Iterator Protocol" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "range" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = range(3)\n", "type(r)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = [0, 1, 2]\n", "type(l)" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n" ] } ], "source": [ "for elem in l:\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n" ] } ], "source": [ "for elem in r:\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2]" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list_iterator" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "it = iter(l)\n", "type(it)" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \n" ] } ], "source": [ "try:\n", " next(it)\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n" ] } ], "source": [ "for elem in l:\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "range" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = range(3)\n", "type(r)" ] }, { "cell_type": "code", "execution_count": 102, "metadata": {}, "outputs": [], "source": [ "it = iter(r)" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \n" ] } ], "source": [ "try:\n", " next(it)\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 115, "metadata": {}, "outputs": [], "source": [ "def my_range(stop):\n", " print('start')\n", " run = 0\n", " while run < stop:\n", " print('before yield', run)\n", " yield run\n", " print('after yield', run)\n", " run += 1\n", " print('stop iteration')" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [], "source": [ "r = my_range(3)" ] }, { "cell_type": "code", "execution_count": 118, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r" ] }, { "cell_type": "code", "execution_count": 119, "metadata": {}, "outputs": [], "source": [ "it = iter(r)" ] }, { "cell_type": "code", "execution_count": 120, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "start\n", "before yield 0\n" ] }, { "data": { "text/plain": [ "0" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 121, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "after yield 0\n", "before yield 1\n" ] }, { "data": { "text/plain": [ "1" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 122, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "after yield 1\n", "before yield 2\n" ] }, { "data": { "text/plain": [ "2" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" } ], "source": [ "next(it)" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \n" ] } ], "source": [ "try:\n", " next(it)\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 125, "metadata": {}, "outputs": [], "source": [ "def wurscht():\n", " yield 0\n", " yield 'doedel'\n", " yield 666.42" ] }, { "cell_type": "code", "execution_count": 126, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "doedel\n", "666.42\n" ] } ], "source": [ "for elem in wurscht():\n", " print(elem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Functions" ] }, { "cell_type": "code", "execution_count": 134, "metadata": {}, "outputs": [], "source": [ "def is_even(n):\n", " if n % 2 == 0:\n", " return True\n", " else:\n", " return False" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "is_even(100)" ] }, { "cell_type": "code", "execution_count": 136, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "is_even(99)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sequential Datatypes" ] }, { "cell_type": "code", "execution_count": 137, "metadata": {}, "outputs": [], "source": [ "s = 'abc'" ] }, { "cell_type": "code", "execution_count": 138, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a\n", "b\n", "c\n" ] } ], "source": [ "for c in s:\n", " print(c)" ] }, { "cell_type": "code", "execution_count": 140, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'a'" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s[0]" ] }, { "cell_type": "code", "execution_count": 141, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'c'" ] }, "execution_count": 141, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s[2]" ] }, { "cell_type": "code", "execution_count": 142, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'b'" ] }, "execution_count": 142, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s[1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## More About Strings" ] }, { "cell_type": "code", "execution_count": 143, "metadata": {}, "outputs": [], "source": [ "s = 'blah'" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'blah'" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s" ] }, { "cell_type": "code", "execution_count": 145, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'blah'" ] }, "execution_count": 145, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'blah'" ] }, { "cell_type": "code", "execution_count": 146, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"doesn't\"" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'doesn\\'t'" ] }, { "cell_type": "code", "execution_count": 148, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"doesn't\"" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"doesn't\"" ] }, { "cell_type": "code", "execution_count": 149, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'sdhcbdhcb\\'kjsdskbh\"akjsdhvksb'" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"sdhcbdhcb'kjsdskbh\\\"akjsdhvksb\"" ] }, { "cell_type": "code", "execution_count": 151, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "abc\n", "def\n" ] } ], "source": [ "s = \"abc\\ndef\"\n", "print(s)" ] }, { "cell_type": "code", "execution_count": 152, "metadata": {}, "outputs": [], "source": [ "path = 'C:\\some\\name'" ] }, { "cell_type": "code", "execution_count": 153, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\n", "ame\n" ] } ], "source": [ "print(path)" ] }, { "cell_type": "code", "execution_count": 154, "metadata": {}, "outputs": [], "source": [ "path = 'C:\\some\\\\name'" ] }, { "cell_type": "code", "execution_count": 155, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\\name\n" ] } ], "source": [ "print(path)" ] }, { "cell_type": "code", "execution_count": 156, "metadata": {}, "outputs": [], "source": [ "path = r'C:\\some\\name'" ] }, { "cell_type": "code", "execution_count": 157, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\some\\name\n" ] } ], "source": [ "print(path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Regular Expressions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Potschert ..." ] }, { "cell_type": "code", "execution_count": 162, "metadata": {}, "outputs": [], "source": [ "line = \" blah . 1234 \\n\"" ] }, { "cell_type": "code", "execution_count": 164, "metadata": {}, "outputs": [], "source": [ "item1, item2 = line.split('.')" ] }, { "cell_type": "code", "execution_count": 165, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(' blah ', ' 1234 \\n')" ] }, "execution_count": 165, "metadata": {}, "output_type": "execute_result" } ], "source": [ "item1, item2" ] }, { "cell_type": "code", "execution_count": 166, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'blah'" ] }, "execution_count": 166, "metadata": {}, "output_type": "execute_result" } ], "source": [ "item1 = item1.strip()\n", "item1" ] }, { "cell_type": "code", "execution_count": 168, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1234" ] }, "execution_count": 168, "metadata": {}, "output_type": "execute_result" } ], "source": [ "int(item2.strip())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Gscheit ..." ] }, { "cell_type": "code", "execution_count": 169, "metadata": {}, "outputs": [], "source": [ "import re" ] }, { "cell_type": "code", "execution_count": 162, "metadata": {}, "outputs": [], "source": [ "line = \" blah . 1234 \\n\"" ] }, { "cell_type": "code", "execution_count": 182, "metadata": {}, "outputs": [], "source": [ "line_re = re.compile(r\"^\\s*(\\S+)\\s*\\.\\s*(\\d+)\\s*$\")" ] }, { "cell_type": "code", "execution_count": 183, "metadata": {}, "outputs": [], "source": [ "match = line_re.search(line)" ] }, { "cell_type": "code", "execution_count": 184, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "re.Match" ] }, "execution_count": 184, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(match)" ] }, { "cell_type": "code", "execution_count": 185, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'blah'" ] }, "execution_count": 185, "metadata": {}, "output_type": "execute_result" } ], "source": [ "match.group(1)" ] }, { "cell_type": "code", "execution_count": 186, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1234'" ] }, "execution_count": 186, "metadata": {}, "output_type": "execute_result" } ], "source": [ "match.group(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Multiline Strings" ] }, { "cell_type": "code", "execution_count": 194, "metadata": {}, "outputs": [], "source": [ "def foo(bar):\n", " '''This complex function foos a bar by\n", " concatenating bar to itself a thousand times'''\n", " return bar*5" ] }, { "cell_type": "code", "execution_count": 195, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'abcabcabcabcabc'" ] }, "execution_count": 195, "metadata": {}, "output_type": "execute_result" } ], "source": [ "foo('abc')" ] }, { "cell_type": "code", "execution_count": 196, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function foo in module __main__:\n", "\n", "foo(bar)\n", " This complex function foos a bar by\n", " concatenating bar to itself a thousand times\n", "\n" ] } ], "source": [ "help(foo)" ] }, { "cell_type": "code", "execution_count": 197, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'This complex function foos a bar by\\n concatenating bar to itself a thousand times'" ] }, "execution_count": 197, "metadata": {}, "output_type": "execute_result" } ], "source": [ "foo.__doc__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### f-Strings" ] }, { "cell_type": "code", "execution_count": 198, "metadata": {}, "outputs": [], "source": [ "a = 1" ] }, { "cell_type": "code", "execution_count": 199, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'blah 1 blah'" ] }, "execution_count": 199, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f'blah {a} blah'" ] }, { "cell_type": "code", "execution_count": 200, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'666 blah'" ] }, "execution_count": 200, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'%d %s' % (666, 'blah')" ] }, { "cell_type": "code", "execution_count": 201, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'666 blah'" ] }, "execution_count": 201, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'{0} {1}'.format(666, 'blah')" ] }, { "cell_type": "code", "execution_count": 203, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'666 blah'" ] }, "execution_count": 203, "metadata": {}, "output_type": "execute_result" } ], "source": [ "i = 666\n", "blah = 'blah'\n", "f'{i} {blah}'" ] }, { "cell_type": "code", "execution_count": 204, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'666 blah'" ] }, "execution_count": 204, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f'{665+1} {\"bla\"+\"h\"}'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Miscellaneous String Methods" ] }, { "cell_type": "code", "execution_count": 205, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 205, "metadata": {}, "output_type": "execute_result" } ], "source": [ "' \\n\\t '.isspace()" ] }, { "cell_type": "code", "execution_count": 206, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 206, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'abc'.isalpha()" ] }, { "cell_type": "code", "execution_count": 207, "metadata": {}, "outputs": [], "source": [ "s = 'mississippi'" ] }, { "cell_type": "code", "execution_count": 208, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 208, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.count('ss')" ] }, { "cell_type": "code", "execution_count": 210, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['.ipynb_checkpoints',\n", " 'notebook-wrapper.rst',\n", " 'notebook.ipynb',\n", " 'agenda.rst.~1~',\n", " 'index.rst.~1~',\n", " 'index.rst',\n", " 'agenda.rst.~2~',\n", " 'agenda.rst']" ] }, "execution_count": 210, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "os.listdir('.')" ] }, { "cell_type": "code", "execution_count": 211, "metadata": {}, "outputs": [], "source": [ "filename = 'data.csv'" ] }, { "cell_type": "code", "execution_count": 212, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 212, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filename.endswith('.csv')" ] }, { "cell_type": "code", "execution_count": 213, "metadata": {}, "outputs": [], "source": [ "s = 'mississippi'" ] }, { "cell_type": "code", "execution_count": 214, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 214, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.count('ss')" ] }, { "cell_type": "code", "execution_count": 215, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 215, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.find('ss')" ] }, { "cell_type": "code", "execution_count": 216, "metadata": {}, "outputs": [], "source": [ "pos = s.find('ss')" ] }, { "cell_type": "code", "execution_count": 217, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 217, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pos" ] }, { "cell_type": "code", "execution_count": 218, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 218, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.find('ss', pos + 1)" ] }, { "cell_type": "code", "execution_count": 219, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-1" ] }, "execution_count": 219, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.find('xx')" ] }, { "cell_type": "code", "execution_count": 220, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 220, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.index('ss')" ] }, { "cell_type": "code", "execution_count": 222, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " substring not found\n" ] } ], "source": [ "try:\n", " s.index('xx')\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### ``split()`` and ``join()``" ] }, { "cell_type": "code", "execution_count": 223, "metadata": {}, "outputs": [], "source": [ "line = 'one:two:three'" ] }, { "cell_type": "code", "execution_count": 224, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['one', 'two', 'three']" ] }, "execution_count": 224, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line.split(':')" ] }, { "cell_type": "code", "execution_count": 227, "metadata": {}, "outputs": [], "source": [ "a, b, c = line.split(':')" ] }, { "cell_type": "code", "execution_count": 228, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('one', 'two', 'three')" ] }, "execution_count": 228, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a, b, c" ] }, { "cell_type": "code", "execution_count": 229, "metadata": {}, "outputs": [], "source": [ "items = ['one', 'two', 'three']" ] }, { "cell_type": "code", "execution_count": 230, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'one:two:three'" ] }, "execution_count": 230, "metadata": {}, "output_type": "execute_result" } ], "source": [ "':'.join(items)" ] }, { "cell_type": "code", "execution_count": 231, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'one:two:three'" ] }, "execution_count": 231, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line" ] }, { "cell_type": "code", "execution_count": 232, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['one', 'two:three']" ] }, "execution_count": 232, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line.split(':', 1)" ] }, { "cell_type": "code", "execution_count": 233, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1: 'one', 2: 'two'}" ] }, "execution_count": 233, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict([(1, 'one'), (2, 'two')])" ] }, { "cell_type": "code", "execution_count": 234, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "' blah '" ] }, "execution_count": 234, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'blah'.center(80)" ] }, { "cell_type": "code", "execution_count": 236, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'xxx yyy'" ] }, "execution_count": 236, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'xxx\\tyyy'.expandtabs()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## More About Lists" ] }, { "cell_type": "code", "execution_count": 237, "metadata": {}, "outputs": [], "source": [ "l = [4, 2, 3.6]" ] }, { "cell_type": "code", "execution_count": 238, "metadata": {}, "outputs": [], "source": [ "l.sort()" ] }, { "cell_type": "code", "execution_count": 239, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 3.6, 4]" ] }, "execution_count": 239, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 240, "metadata": {}, "outputs": [], "source": [ "l = [2, 'eins']" ] }, { "cell_type": "code", "execution_count": 242, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " '<' not supported between instances of 'str' and 'int'\n" ] } ], "source": [ "try:\n", " l.sort()\n", "except Exception as e:\n", " print(type(e), e)" ] }, { "cell_type": "code", "execution_count": 243, "metadata": {}, "outputs": [], "source": [ "l = [2, 1, 3, 7, 4]" ] }, { "cell_type": "code", "execution_count": 244, "metadata": {}, "outputs": [], "source": [ "l.sort(reverse=True)" ] }, { "cell_type": "code", "execution_count": 245, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[7, 4, 3, 2, 1]" ] }, "execution_count": 245, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 246, "metadata": {}, "outputs": [], "source": [ "l.reverse()" ] }, { "cell_type": "code", "execution_count": 247, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 4, 7]" ] }, "execution_count": 247, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 248, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 4, 9, 16, 49]" ] }, "execution_count": 248, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[i**2 for i in l]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## More About Dictionaries" ] }, { "cell_type": "code", "execution_count": 249, "metadata": {}, "outputs": [], "source": [ "d = {'one': 1, 'two': 2}" ] }, { "cell_type": "code", "execution_count": 250, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 250, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d['one']" ] }, { "cell_type": "code", "execution_count": 252, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 252, "metadata": {}, "output_type": "execute_result" } ], "source": [ "if 'three' in d:\n", " v = d['three']\n", "else:\n", " v = 3\n", "v" ] }, { "cell_type": "code", "execution_count": 256, "metadata": {}, "outputs": [], "source": [ "v = d.get('three', 3)" ] }, { "cell_type": "code", "execution_count": 257, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n" ] } ], "source": [ "print(v)" ] }, { "cell_type": "code", "execution_count": 262, "metadata": {}, "outputs": [], "source": [ "if 'three' in d:\n", " v = d['three']\n", "else:\n", " d['three'] = 3\n", " v = d['three']" ] }, { "cell_type": "code", "execution_count": 260, "metadata": {}, "outputs": [], "source": [ "del d['three']" ] }, { "cell_type": "code", "execution_count": 264, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 264, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.setdefault('three', 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pythonicity (``enumerate()``)" ] }, { "cell_type": "code", "execution_count": 265, "metadata": {}, "outputs": [], "source": [ "l = ['Joerg', 'Caro', 'Johanna', 'Philipp']" ] }, { "cell_type": "code", "execution_count": 268, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 Joerg\n", "1 Caro\n", "2 Johanna\n", "3 Philipp\n" ] } ], "source": [ "lineno = 0\n", "for name in l:\n", " print(lineno, name)\n", " lineno += 1" ] }, { "cell_type": "code", "execution_count": 270, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0, 'Joerg')\n", "(1, 'Caro')\n", "(2, 'Johanna')\n", "(3, 'Philipp')\n" ] } ], "source": [ "for elem in enumerate(l):\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 271, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 Joerg\n", "1 Caro\n", "2 Johanna\n", "3 Philipp\n" ] } ], "source": [ "for lineno, name in enumerate(l):\n", " print(lineno, name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ``pandas``, ``matplotlib``" ] }, { "cell_type": "code", "execution_count": 273, "metadata": {}, "outputs": [], "source": [ "import pandas" ] }, { "cell_type": "code", "execution_count": 277, "metadata": {}, "outputs": [], "source": [ "df = pandas.read_csv('data.csv', encoding='utf-16', delimiter='\\t')" ] }, { "cell_type": "code", "execution_count": 278, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ScanZeit101 <MP_left 1> (C)102 <MP_left 2> (C)103 <MP_left 3> (C)104 <MP_top> (C)105 <MP_right 1> (C)106 <MP_righ 2> (C)107 <MP_righ 3> (C)108 <Brenner Kupfer> (C)109 <Brenner Messing> (C)110 <Koax Oberflaeche 15> (C)111 <Koax Oberflaeche 100> (C)112 <Gasduese> (C)113 <FSC Koax 15> (C)114 <FSC> (C)115 <Zellentemp> (C)117 <Raumtemp> (C)120 <strom> (VDC)
0101.03.2022 10:15:3828.54028.27429.07728.34728.87728.81129.31332.09031.88328.74627.60923.43724.71630.50023.28821.2193.76220
1201.03.2022 10:15:4828.52928.26029.04528.29928.82828.77029.27331.96431.77128.76827.66824.45924.69530.46523.47621.1733.77849
2301.03.2022 10:15:5828.47628.22028.99428.26428.81228.72729.19831.88731.65528.67127.53724.22524.68130.43323.48221.0863.81216
3401.03.2022 10:16:0828.46528.20928.93528.21028.78828.70629.12631.77431.54028.61527.41123.55224.65730.40923.27821.1543.99354
4501.03.2022 10:16:1828.55628.25528.94028.17828.92228.81629.32732.30032.37128.55327.445317.34624.69730.51130.59121.116373.92051
............................................................
34834901.03.2022 11:13:3850.11548.60751.65045.00050.94951.04053.54487.07792.66551.47145.35426.29933.91840.81623.03520.9464.82874
34935001.03.2022 11:13:4849.99448.54551.46744.94950.93951.01153.43186.59192.07551.29745.14158.90933.80440.77723.00620.9264.78855
35035101.03.2022 11:13:5849.93348.51051.39544.92950.89850.97153.31486.09891.44251.03645.007181.21133.70140.71622.99120.9914.76466
35135201.03.2022 11:14:0849.96748.44751.42244.88150.81650.86952.86285.58390.81350.83944.9092.09133.70640.65522.92121.0104.64736
35235301.03.2022 11:14:1849.81248.35251.31644.78150.68050.82752.94185.11890.16450.84444.964-124.13233.48340.59423.25920.8914.65062
\n", "

353 rows × 19 columns

\n", "
" ], "text/plain": [ " Scan Zeit 101 (C) 102 (C) \\\n", "0 1 01.03.2022 10:15:38 28.540 28.274 \n", "1 2 01.03.2022 10:15:48 28.529 28.260 \n", "2 3 01.03.2022 10:15:58 28.476 28.220 \n", "3 4 01.03.2022 10:16:08 28.465 28.209 \n", "4 5 01.03.2022 10:16:18 28.556 28.255 \n", ".. ... ... ... ... \n", "348 349 01.03.2022 11:13:38 50.115 48.607 \n", "349 350 01.03.2022 11:13:48 49.994 48.545 \n", "350 351 01.03.2022 11:13:58 49.933 48.510 \n", "351 352 01.03.2022 11:14:08 49.967 48.447 \n", "352 353 01.03.2022 11:14:18 49.812 48.352 \n", "\n", " 103 (C) 104 (C) 105 (C) \\\n", "0 29.077 28.347 28.877 \n", "1 29.045 28.299 28.828 \n", "2 28.994 28.264 28.812 \n", "3 28.935 28.210 28.788 \n", "4 28.940 28.178 28.922 \n", ".. ... ... ... \n", "348 51.650 45.000 50.949 \n", "349 51.467 44.949 50.939 \n", "350 51.395 44.929 50.898 \n", "351 51.422 44.881 50.816 \n", "352 51.316 44.781 50.680 \n", "\n", " 106 (C) 107 (C) 108 (C) \\\n", "0 28.811 29.313 32.090 \n", "1 28.770 29.273 31.964 \n", "2 28.727 29.198 31.887 \n", "3 28.706 29.126 31.774 \n", "4 28.816 29.327 32.300 \n", ".. ... ... ... \n", "348 51.040 53.544 87.077 \n", "349 51.011 53.431 86.591 \n", "350 50.971 53.314 86.098 \n", "351 50.869 52.862 85.583 \n", "352 50.827 52.941 85.118 \n", "\n", " 109 (C) 110 (C) \\\n", "0 31.883 28.746 \n", "1 31.771 28.768 \n", "2 31.655 28.671 \n", "3 31.540 28.615 \n", "4 32.371 28.553 \n", ".. ... ... \n", "348 92.665 51.471 \n", "349 92.075 51.297 \n", "350 91.442 51.036 \n", "351 90.813 50.839 \n", "352 90.164 50.844 \n", "\n", " 111 (C) 112 (C) \\\n", "0 27.609 23.437 \n", "1 27.668 24.459 \n", "2 27.537 24.225 \n", "3 27.411 23.552 \n", "4 27.445 317.346 \n", ".. ... ... \n", "348 45.354 26.299 \n", "349 45.141 58.909 \n", "350 45.007 181.211 \n", "351 44.909 2.091 \n", "352 44.964 -124.132 \n", "\n", " 113 (C) 114 (C) 115 (C) \\\n", "0 24.716 30.500 23.288 \n", "1 24.695 30.465 23.476 \n", "2 24.681 30.433 23.482 \n", "3 24.657 30.409 23.278 \n", "4 24.697 30.511 30.591 \n", ".. ... ... ... \n", "348 33.918 40.816 23.035 \n", "349 33.804 40.777 23.006 \n", "350 33.701 40.716 22.991 \n", "351 33.706 40.655 22.921 \n", "352 33.483 40.594 23.259 \n", "\n", " 117 (C) 120 (VDC) \n", "0 21.219 3.76220 \n", "1 21.173 3.77849 \n", "2 21.086 3.81216 \n", "3 21.154 3.99354 \n", "4 21.116 373.92051 \n", ".. ... ... \n", "348 20.946 4.82874 \n", "349 20.926 4.78855 \n", "350 20.991 4.76466 \n", "351 21.010 4.64736 \n", "352 20.891 4.65062 \n", "\n", "[353 rows x 19 columns]" ] }, "execution_count": 278, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 284, "metadata": {}, "outputs": [], "source": [ "timestamps = df['Zeit']" ] }, { "cell_type": "code", "execution_count": 289, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 01.03.2022 10:15:38\n", "1 01.03.2022 10:15:48\n", "2 01.03.2022 10:15:58\n", "3 01.03.2022 10:16:08\n", "4 01.03.2022 10:16:18\n", " ... \n", "348 01.03.2022 11:13:38\n", "349 01.03.2022 11:13:48\n", "350 01.03.2022 11:13:58\n", "351 01.03.2022 11:14:08\n", "352 01.03.2022 11:14:18\n", "Name: Zeit, Length: 353, dtype: object" ] }, "execution_count": 289, "metadata": {}, "output_type": "execute_result" } ], "source": [ "timestamps" ] }, { "cell_type": "code", "execution_count": 291, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pandas.core.series.Series" ] }, "execution_count": 291, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(timestamps)" ] }, { "cell_type": "code", "execution_count": 281, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime" ] }, { "cell_type": "code", "execution_count": 287, "metadata": {}, "outputs": [], "source": [ "def transform_ts(ts):\n", " dt = datetime.strptime(ts, '%d.%m.%Y %H:%M:%S')\n", " return dt.timestamp()" ] }, { "cell_type": "code", "execution_count": 298, "metadata": {}, "outputs": [], "source": [ "transformed_timestamps = timestamps.apply(transform_ts)" ] }, { "cell_type": "code", "execution_count": 299, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 1.646126e+09\n", "1 1.646126e+09\n", "2 1.646126e+09\n", "3 1.646126e+09\n", "4 1.646126e+09\n", " ... \n", "348 1.646130e+09\n", "349 1.646130e+09\n", "350 1.646130e+09\n", "351 1.646130e+09\n", "352 1.646130e+09\n", "Name: Zeit, Length: 353, dtype: float64" ] }, "execution_count": 299, "metadata": {}, "output_type": "execute_result" } ], "source": [ "transformed_timestamps" ] }, { "cell_type": "code", "execution_count": 300, "metadata": {}, "outputs": [], "source": [ "df['Zeit'] = transformed_timestamps" ] }, { "cell_type": "code", "execution_count": 303, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ScanZeit101 <MP_left 1> (C)102 <MP_left 2> (C)103 <MP_left 3> (C)104 <MP_top> (C)105 <MP_right 1> (C)106 <MP_righ 2> (C)107 <MP_righ 3> (C)108 <Brenner Kupfer> (C)109 <Brenner Messing> (C)110 <Koax Oberflaeche 15> (C)111 <Koax Oberflaeche 100> (C)112 <Gasduese> (C)113 <FSC Koax 15> (C)114 <FSC> (C)115 <Zellentemp> (C)117 <Raumtemp> (C)120 <strom> (VDC)
011.646126e+0928.54028.27429.07728.34728.87728.81129.31332.09031.88328.74627.60923.43724.71630.50023.28821.2193.76220
121.646126e+0928.52928.26029.04528.29928.82828.77029.27331.96431.77128.76827.66824.45924.69530.46523.47621.1733.77849
231.646126e+0928.47628.22028.99428.26428.81228.72729.19831.88731.65528.67127.53724.22524.68130.43323.48221.0863.81216
341.646126e+0928.46528.20928.93528.21028.78828.70629.12631.77431.54028.61527.41123.55224.65730.40923.27821.1543.99354
451.646126e+0928.55628.25528.94028.17828.92228.81629.32732.30032.37128.55327.445317.34624.69730.51130.59121.116373.92051
............................................................
3483491.646130e+0950.11548.60751.65045.00050.94951.04053.54487.07792.66551.47145.35426.29933.91840.81623.03520.9464.82874
3493501.646130e+0949.99448.54551.46744.94950.93951.01153.43186.59192.07551.29745.14158.90933.80440.77723.00620.9264.78855
3503511.646130e+0949.93348.51051.39544.92950.89850.97153.31486.09891.44251.03645.007181.21133.70140.71622.99120.9914.76466
3513521.646130e+0949.96748.44751.42244.88150.81650.86952.86285.58390.81350.83944.9092.09133.70640.65522.92121.0104.64736
3523531.646130e+0949.81248.35251.31644.78150.68050.82752.94185.11890.16450.84444.964-124.13233.48340.59423.25920.8914.65062
\n", "

353 rows × 19 columns

\n", "
" ], "text/plain": [ " Scan Zeit 101 (C) 102 (C) \\\n", "0 1 1.646126e+09 28.540 28.274 \n", "1 2 1.646126e+09 28.529 28.260 \n", "2 3 1.646126e+09 28.476 28.220 \n", "3 4 1.646126e+09 28.465 28.209 \n", "4 5 1.646126e+09 28.556 28.255 \n", ".. ... ... ... ... \n", "348 349 1.646130e+09 50.115 48.607 \n", "349 350 1.646130e+09 49.994 48.545 \n", "350 351 1.646130e+09 49.933 48.510 \n", "351 352 1.646130e+09 49.967 48.447 \n", "352 353 1.646130e+09 49.812 48.352 \n", "\n", " 103 (C) 104 (C) 105 (C) \\\n", "0 29.077 28.347 28.877 \n", "1 29.045 28.299 28.828 \n", "2 28.994 28.264 28.812 \n", "3 28.935 28.210 28.788 \n", "4 28.940 28.178 28.922 \n", ".. ... ... ... \n", "348 51.650 45.000 50.949 \n", "349 51.467 44.949 50.939 \n", "350 51.395 44.929 50.898 \n", "351 51.422 44.881 50.816 \n", "352 51.316 44.781 50.680 \n", "\n", " 106 (C) 107 (C) 108 (C) \\\n", "0 28.811 29.313 32.090 \n", "1 28.770 29.273 31.964 \n", "2 28.727 29.198 31.887 \n", "3 28.706 29.126 31.774 \n", "4 28.816 29.327 32.300 \n", ".. ... ... ... \n", "348 51.040 53.544 87.077 \n", "349 51.011 53.431 86.591 \n", "350 50.971 53.314 86.098 \n", "351 50.869 52.862 85.583 \n", "352 50.827 52.941 85.118 \n", "\n", " 109 (C) 110 (C) \\\n", "0 31.883 28.746 \n", "1 31.771 28.768 \n", "2 31.655 28.671 \n", "3 31.540 28.615 \n", "4 32.371 28.553 \n", ".. ... ... \n", "348 92.665 51.471 \n", "349 92.075 51.297 \n", "350 91.442 51.036 \n", "351 90.813 50.839 \n", "352 90.164 50.844 \n", "\n", " 111 (C) 112 (C) \\\n", "0 27.609 23.437 \n", "1 27.668 24.459 \n", "2 27.537 24.225 \n", "3 27.411 23.552 \n", "4 27.445 317.346 \n", ".. ... ... \n", "348 45.354 26.299 \n", "349 45.141 58.909 \n", "350 45.007 181.211 \n", "351 44.909 2.091 \n", "352 44.964 -124.132 \n", "\n", " 113 (C) 114 (C) 115 (C) \\\n", "0 24.716 30.500 23.288 \n", "1 24.695 30.465 23.476 \n", "2 24.681 30.433 23.482 \n", "3 24.657 30.409 23.278 \n", "4 24.697 30.511 30.591 \n", ".. ... ... ... \n", "348 33.918 40.816 23.035 \n", "349 33.804 40.777 23.006 \n", "350 33.701 40.716 22.991 \n", "351 33.706 40.655 22.921 \n", "352 33.483 40.594 23.259 \n", "\n", " 117 (C) 120 (VDC) \n", "0 21.219 3.76220 \n", "1 21.173 3.77849 \n", "2 21.086 3.81216 \n", "3 21.154 3.99354 \n", "4 21.116 373.92051 \n", ".. ... ... \n", "348 20.946 4.82874 \n", "349 20.926 4.78855 \n", "350 20.991 4.76466 \n", "351 21.010 4.64736 \n", "352 20.891 4.65062 \n", "\n", "[353 rows x 19 columns]" ] }, "execution_count": 303, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 306, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Scan', 'Zeit', '101 (C)', '102 (C)',\n", " '103 (C)', '104 (C)', '105 (C)',\n", " '106 (C)', '107 (C)',\n", " '108 (C)', '109 (C)',\n", " '110 (C)', '111 (C)',\n", " '112 (C)', '113 (C)', '114 (C)',\n", " '115 (C)', '117 (C)', '120 (VDC)'],\n", " dtype='object')" ] }, "execution_count": 306, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.columns" ] }, { "cell_type": "code", "execution_count": 307, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 28.540\n", "1 28.529\n", "2 28.476\n", "3 28.465\n", "4 28.556\n", " ... \n", "348 50.115\n", "349 49.994\n", "350 49.933\n", "351 49.967\n", "352 49.812\n", "Name: 101 (C), Length: 353, dtype: float64" ] }, "execution_count": 307, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df[df.columns[2]]" ] }, { "cell_type": "code", "execution_count": 308, "metadata": {}, "outputs": [], "source": [ "timestamps = df[df.columns[1]]" ] }, { "cell_type": "code", "execution_count": 311, "metadata": {}, "outputs": [], "source": [ "mpleft_1 = df[df.columns[2]]" ] }, { "cell_type": "code", "execution_count": 312, "metadata": {}, "outputs": [], "source": [ "mpleft_2 = df[df.columns[3]]" ] }, { "cell_type": "code", "execution_count": 315, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 317, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 318, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 318, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAEFCAYAAAD69rxNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAm00lEQVR4nO3deXhU5d3G8e8v+wJkgbDvsu9IRHEXN0QF7GutXVyqdanLq7ZatdpqF2tbrdauFrWKrQqIC762CCgoWBUBCWsSiOxbEpaQQMg6z/vHHGnEAAFmcmaS+3NduTJz5szMPSeTOyfPnMWcc4iISPSJ8TuAiIgcGxW4iEiUUoGLiEQpFbiISJRSgYuIRKm4xnyyNm3auO7duzfmU4qIRL3FixfvcM5lHTy9UQu8e/fuLFq0qDGfUkQk6pnZhvqmawhFRCRKqcBFRKKUClxEJEqpwEVEopQKXEQkSqnARUSilApcRCRKqcBFpEnbW1nDtMWbqaoJ+B0l5FTgItKkPTl7NXe/upSH3lrhd5SQU4GLSFSprKll5dY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7IM60/9uZkVmtuKgx3jMe/xlZvaGmaU3IP9vvANqrTCzbzTkNavARSTqeIX6wkGTVxA8hsm8I9z9KeAd51w/YCiQW+dxuwAXEDxkwRfT0oG/AOOccwOBr9d5rBeof+/d2cAg59wQgpsV3n+E13MxwR0fhxHc5v9uM2t1hNehAheRpsE5l+ucyz/cPA04kN2TwI/48i7+3wJed85t9O7zxd6jOOfmAbvqyTLL/fd4Op8Q3CsTM4v11s4XemvnN3nzDADmOedqnHP7CG57fsTDOqjARaQ5OeSB7MxsPLDFObf0oPv0ATLM7H0zW2xmVx/lc15HcC9TgOsJHojsJILHr7nBzHoQ3IFojJmleEM35/Dl3fLrFXekGUREIoWZLSC4B2oLINPMcryb7nXOzWzAQ3xxILvbnXMLzOwp4D4zexT4McHhk/ruM4Lg4ZGTgY/N7BPn3OoG5H0AqAFe8iZdAAwxs8u962lAb+fcLDM7CfiI4B+Yjzno4F+HejEiIlHBOXcyBMfAgWudc9ce5UPUdyC7+wgedbAHsDR4iHc6A5+Z2UjvPju9oY19ZjaP4Nj5YQvczK4FLiG4a/4XQzJG8I/HV/7YOOceAR7x7vvykR4fNIQiIs2Ic247sMnM+nqTzgVWOeeWO+faOue6O+e6EyztE735pwOnm1mcd7zwk6nzwWd9zGwMwbH0cc658jo3zQS+b2bx3nx9zCzVGxtv7U0bAgwheHjbw9IauIg0CWZ2GfBHIAv4l5nlOOcuNLOOwLPOuS/OaXk78JJ3zPq1wHcP97jOuVwze4fgB4sB77FWeM/5CnA20MbMNgMPOeeeA/5EcKhntrdG/4lz7mbgWaA7wbV7IzhcMgGIB+Z785YC36nzIeihX7MOZiUiEp00hCIiEqVU4CIiUUoFLiISpVTgIiJRSgUuIhKlVOAiIlFKBS4iEqX+HyMjHWGgOYBXAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.plot(timestamps, mpleft_1)" ] }, { "cell_type": "code", "execution_count": 319, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 319, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAEFCAYAAAD69rxNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAmfklEQVR4nO3dd3xV9f3H8dcnk4RAQiBhBQh7TyMo7lFR3P25tWLdrW3t0KrV1tr+bKvWWq2/1lqto8WJs9YBgrhlr7DDDCuEhJBF5v3+/rhHjJhAIDc59ybv5+ORR+4999x73/dy8+bc71nmnENERCJPlN8BRETk8KjARUQilApcRCRCqcBFRCKUClxEJELFtOSTdenSxWVmZrbkU4qIRLwFCxbscs6l7T+9RQs8MzOT+fPnt+RTiohEPDPbVN/0RhW4mW0ESoBaoMY5l2VmqcCLQCawEbjIObc7FGFFROTgDmUM/CTn3BjnXJZ3/XZgpnNuIDDTuy4iIi2kKSsxzwWe8S4/A5zX5DQiItJojS1wB0w3swVmdr03ratzbrt3eQfQNeTpRESkQY1diXmsc26rmaUDM8xsVd0bnXPOzOo9qIpX+NcD9O7du0lhRUTkK41aAnfObfV+7wReA8YDeWbWHcD7vbOB+z7unMtyzmWlpX1jKxgRETlMBy1wM2tvZh2+vAycBmQDbwJTvNmmAG80V0gREfmmxgyhdAVeM7Mv53/OOfeumc0DXjKza4BNwEXNF1NEpPGKyquIjjI6tItla9FeZq3M48TB6fRKTfQ7WkgdtMCdc+uB0fVMLwBOaY5QIiKNtXFXGQ+9v4YO7WI4fmAaOfmlPPHxBpxzmBm7y6twDuKiV/LdYzKZ0C+VET2SWZdfRlxMFGWVNQzt3pG0DvF+v5RDZi15QoesrCynPTFF5HAUV1SzcNNu1uWX8W72dq45th8bC8r4y8y1mBkB5yivqgVgQHoSvVMTSYyLpm+X9pw0JJ1HZq5l9ur8Bh+/Z0oCo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7f+M/GOXcvcK933+cO9vigIRQRaUOcczuAXDMb7E06BVjhnFvmnEt3zmU65zIJlvY4b/43gGPNLMY7XvgE6qz4rI+ZnU5wLP0c51x5nZveA75nZrHefIPMrL03Nt7ZmzYKGEXw8LYHpCVwEWkVzOx84C9AGvBfM1vsnJtkZj2AJ5xzX57T8ofAVO+Y9euB7x7ocZ1zK83sXYIrFgPeY2V7z/k8cCLQxcy2AHc7554EHiU41DPDW6L/wjl3I/AEkElw6d4IDpecB8QCH3vzFgNX1FkJ2vBr1sGsREQik4ZQREQilApcRCRCqcBFRCKUClxEJEKpwEVEIpQKXEQkQqnARUQi1P8DMKLx5SHBZ7YAAAAASUVORK5CYII=\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.plot(timestamps, mpleft_2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ``exec()``" ] }, { "cell_type": "code", "execution_count": 322, "metadata": {}, "outputs": [], "source": [ "code = 'print(\"hallo\")'" ] }, { "cell_type": "code", "execution_count": 323, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hallo\n" ] } ], "source": [ "exec(code)" ] }, { "cell_type": "code", "execution_count": 324, "metadata": {}, "outputs": [], "source": [ "code = '''\n", "def add(l, r):\n", " return l+r\n", "'''" ] }, { "cell_type": "code", "execution_count": 325, "metadata": {}, "outputs": [], "source": [ "exec(code)" ] }, { "cell_type": "code", "execution_count": 326, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 326, "metadata": {}, "output_type": "execute_result" } ], "source": [ "add(1, 2)" ] }, { "cell_type": "code", "execution_count": 330, "metadata": {}, "outputs": [], "source": [ "code = '''\n", "eine_variable = 1\n", "noch_eine_variable = 2\n", "'''" ] }, { "cell_type": "code", "execution_count": 333, "metadata": {}, "outputs": [], "source": [ "context = {}" ] }, { "cell_type": "code", "execution_count": 334, "metadata": {}, "outputs": [], "source": [ "exec(code, context)" ] }, { "cell_type": "code", "execution_count": 335, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 335, "metadata": {}, "output_type": "execute_result" } ], "source": [ "context['eine_variable']" ] }, { "cell_type": "code", "execution_count": 336, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 336, "metadata": {}, "output_type": "execute_result" } ], "source": [ "context['noch_eine_variable']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comprehensions (List, Dictionary, Set)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### List Comprehension" ] }, { "cell_type": "code", "execution_count": 337, "metadata": {}, "outputs": [], "source": [ "l = [0, 1, 2, 3, 4, 5]" ] }, { "cell_type": "code", "execution_count": 338, "metadata": {}, "outputs": [], "source": [ "l = list(range(6))" ] }, { "cell_type": "code", "execution_count": 339, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4, 5]" ] }, "execution_count": 339, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 340, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 4, 9, 16, 25]" ] }, "execution_count": 340, "metadata": {}, "output_type": "execute_result" } ], "source": [ "squares = []\n", "for i in l:\n", " squares.append(i**2)\n", "squares" ] }, { "cell_type": "code", "execution_count": 341, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 4, 9, 16, 25]" ] }, "execution_count": 341, "metadata": {}, "output_type": "execute_result" } ], "source": [ "squares = [i**2 for i in l]\n", "squares" ] }, { "cell_type": "code", "execution_count": 342, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 4, 16]" ] }, "execution_count": 342, "metadata": {}, "output_type": "execute_result" } ], "source": [ "even_squares = [i**2 for i in l if i%2 == 0]\n", "even_squares" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ``filter()``" ] }, { "cell_type": "code", "execution_count": 344, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4, 5]" ] }, "execution_count": 344, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 345, "metadata": {}, "outputs": [], "source": [ "def even_pred(n):\n", " return n%2 == 0\n", "even = filter(even_pred, l)" ] }, { "cell_type": "code", "execution_count": 347, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 347, "metadata": {}, "output_type": "execute_result" } ], "source": [ "even" ] }, { "cell_type": "code", "execution_count": 348, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "2\n", "4\n" ] } ], "source": [ "for elem in even:\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 349, "metadata": {}, "outputs": [], "source": [ "even = [i for i in l if i%2 == 0]" ] }, { "cell_type": "code", "execution_count": 350, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 2, 4]" ] }, "execution_count": 350, "metadata": {}, "output_type": "execute_result" } ], "source": [ "even" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generator Expression" ] }, { "cell_type": "code", "execution_count": 351, "metadata": {}, "outputs": [], "source": [ "even = (i for i in l if i%2 == 0)" ] }, { "cell_type": "code", "execution_count": 352, "metadata": {}, "outputs": [ { "data": { "text/plain": [ " at 0x7f48a95250e0>" ] }, "execution_count": 352, "metadata": {}, "output_type": "execute_result" } ], "source": [ "even" ] }, { "cell_type": "code", "execution_count": 353, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "2\n", "4\n" ] } ], "source": [ "for elem in even:\n", " print(elem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dictionary Comprehension" ] }, { "cell_type": "code", "execution_count": 354, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4, 5]" ] }, "execution_count": 354, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "dict i:i**2" ] }, { "cell_type": "code", "execution_count": 355, "metadata": {}, "outputs": [], "source": [ "squaredict = {i: i**2 for i in l}" ] }, { "cell_type": "code", "execution_count": 357, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}" ] }, "execution_count": 357, "metadata": {}, "output_type": "execute_result" } ], "source": [ "squaredict" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set Comprehension" ] }, { "cell_type": "code", "execution_count": 358, "metadata": {}, "outputs": [], "source": [ "squaresset = {i**2 for i in range(15)}" ] }, { "cell_type": "code", "execution_count": 359, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196}" ] }, "execution_count": 359, "metadata": {}, "output_type": "execute_result" } ], "source": [ "squaresset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ``zip()``, And Dictionaries" ] }, { "cell_type": "code", "execution_count": 360, "metadata": {}, "outputs": [], "source": [ "keys = ['one', 'two', 'three']\n", "values = range(1,4)" ] }, { "cell_type": "code", "execution_count": 361, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'one': 1, 'two': 2, 'three': 3}" ] }, "execution_count": 361, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{k: v for k, v in zip(keys, values)}" ] }, { "cell_type": "code", "execution_count": 362, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('one', 1)\n", "('two', 2)\n", "('three', 3)\n" ] } ], "source": [ "for elem in zip(keys, values):\n", " print(elem)" ] }, { "cell_type": "code", "execution_count": 363, "metadata": {}, "outputs": [], "source": [ "values = range(6)" ] }, { "cell_type": "code", "execution_count": 367, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('one', 0)\n", "('two', 2)\n", "('three', 4)\n" ] } ], "source": [ "for elem in zip(keys, (v for i, v in enumerate(values) if i%2 == 0)):\n", " print(elem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## File IO" ] }, { "cell_type": "code", "execution_count": 368, "metadata": {}, "outputs": [], "source": [ "f = open('/etc/passwd')" ] }, { "cell_type": "code", "execution_count": 369, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'root:x:0:0'" ] }, "execution_count": 369, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.read(10)" ] }, { "cell_type": "code", "execution_count": 370, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "':root'" ] }, "execution_count": 370, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.read(5)" ] }, { "cell_type": "code", "execution_count": 371, "metadata": {}, "outputs": [], "source": [ "f.close()" ] }, { "cell_type": "code", "execution_count": 375, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "root:x:0:0:root:/root:/bin/bash\n", "\n" ] } ], "source": [ "with open('/etc/passwd') as f:\n", " print(f.readline())" ] }, { "cell_type": "code", "execution_count": 376, "metadata": {}, "outputs": [], "source": [ "f = open('/etc/passwd')" ] }, { "cell_type": "code", "execution_count": 377, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'root:x:0:0:root:/root:/bin/bash\\n'" ] }, "execution_count": 377, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.readline()" ] }, { "cell_type": "code", "execution_count": 378, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'bin:x:1:1:bin:/bin:/sbin/nologin\\n'" ] }, "execution_count": 378, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.readline()" ] }, { "cell_type": "code", "execution_count": 379, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "daemon:x:2:2:daemon:/sbin:/sbin/nologin\n", "\n", "adm:x:3:4:adm:/var/adm:/sbin/nologin\n", "\n", "lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n", "\n", "sync:x:5:0:sync:/sbin:/bin/sync\n", "\n", "shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n", "\n", "halt:x:7:0:halt:/sbin:/sbin/halt\n", "\n", "mail:x:8:12:mail:/var/spool/mail:/sbin/nologin\n", "\n", "operator:x:11:0:operator:/root:/sbin/nologin\n", "\n", "games:x:12:100:games:/usr/games:/sbin/nologin\n", "\n", "ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin\n", "\n", "nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin\n", "\n", "dbus:x:81:81:System message bus:/:/sbin/nologin\n", "\n", "apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin\n", "\n", "tss:x:59:59:Account used for TPM access:/dev/null:/sbin/nologin\n", "\n", "systemd-network:x:192:192:systemd Network Management:/:/usr/sbin/nologin\n", "\n", "systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/usr/sbin/nologin\n", "\n", "systemd-resolve:x:193:193:systemd Resolver:/:/usr/sbin/nologin\n", "\n", "qemu:x:107:107:qemu user:/:/sbin/nologin\n", "\n", "polkitd:x:998:997:User for polkitd:/:/sbin/nologin\n", "\n", "avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin\n", "\n", "unbound:x:997:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin\n", "\n", "nm-openconnect:x:996:994:NetworkManager user for OpenConnect:/:/sbin/nologin\n", "\n", "geoclue:x:995:993:User for geoclue:/var/lib/geoclue:/sbin/nologin\n", "\n", "usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin\n", "\n", "gluster:x:994:992:GlusterFS daemons:/run/gluster:/sbin/nologin\n", "\n", "rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin\n", "\n", "chrony:x:993:990::/var/lib/chrony:/sbin/nologin\n", "\n", "saslauth:x:992:76:Saslauthd user:/run/saslauthd:/sbin/nologin\n", "\n", "dnsmasq:x:991:989:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin\n", "\n", "rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin\n", "\n", "colord:x:990:988:User for colord:/var/lib/colord:/sbin/nologin\n", "\n", "rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin\n", "\n", "openvpn:x:989:987:OpenVPN:/etc/openvpn:/sbin/nologin\n", "\n", "nm-openvpn:x:988:986:Default user for running openvpn spawned by NetworkManager:/:/sbin/nologin\n", "\n", "pipewire:x:987:985:PipeWire System Daemon:/var/run/pipewire:/sbin/nologin\n", "\n", "abrt:x:173:173::/etc/abrt:/sbin/nologin\n", "\n", "flatpak:x:986:983:User for flatpak system helper:/:/sbin/nologin\n", "\n", "gdm:x:42:42:GNOME Display Manager:/var/lib/gdm:/sbin/nologin\n", "\n", "gnome-initial-setup:x:985:982::/run/gnome-initial-setup/:/sbin/nologin\n", "\n", "vboxadd:x:984:1::/var/run/vboxadd:/sbin/nologin\n", "\n", "sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/sbin/nologin\n", "\n", "tcpdump:x:72:72::/:/sbin/nologin\n", "\n", "jfasch:x:1000:1000:Jörg Faschingbauer:/home/jfasch:/bin/bash\n", "\n", "systemd-coredump:x:978:978:systemd Core Dumper:/:/usr/sbin/nologin\n", "\n", "systemd-timesync:x:977:977:systemd Time Synchronization:/:/usr/sbin/nologin\n", "\n", "mosquitto:x:976:976:Mosquitto Broker:/etc/mosquitto:/sbin/nologin\n", "\n" ] } ], "source": [ "for line in f:\n", " print(line)" ] }, { "cell_type": "code", "execution_count": 383, "metadata": {}, "outputs": [], "source": [ "f = open('/etc/passwd', encoding='ascii')" ] }, { "cell_type": "code", "execution_count": 384, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 'ascii' codec can't decode byte 0xc3 in position 2440: ordinal not in range(128)\n" ] } ], "source": [ "try:\n", " f.read()\n", "except Exception as e:\n", " print(type(e), e)" ] } ], "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.10.11" } }, "nbformat": 4, "nbformat_minor": 4 }