From 6a7c84d99d5ae93cef5d1a75c3f27ea56479a3d0 Mon Sep 17 00:00:00 2001 From: bimoprasetyoafif Date: Sat, 19 Oct 2019 16:28:53 +0700 Subject: [PATCH] adding new tutorial : function --- class2.ipynb | 827 +-------------------------------------------------- 1 file changed, 1 insertion(+), 826 deletions(-) diff --git a/class2.ipynb b/class2.ipynb index 0be32d0..9288202 100644 --- a/class2.ipynb +++ b/class2.ipynb @@ -1,826 +1 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\"It's a string\"" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\"It's a string\"" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'It \"wow\" a string'" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "'It \"wow\" a string'" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "t = 'hello this is long string ''python wow this is string'" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello this is long string python wow this is string\n" - ] - } - ], - "source": [ - "print(t)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'h'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "'hello'[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'hel'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "'hello'[0:3]" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'hello'" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "'hello'[0:2] + 'hello'[2:len('hello')]" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len('hello')" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'str' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m'jello'\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'h'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" - ] - } - ], - "source": [ - "'jello'[0] = 'h'" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "x = 'hello'" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello 4434715624\n" - ] - } - ], - "source": [ - "print(x , id(x))" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "x = 'hello' + 'python'" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hellopython 4435060656\n" - ] - } - ], - "source": [ - "print(x, id(x))" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4396779584\n" - ] - } - ], - "source": [ - "x = 5\n", - "print(id(5))" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [], - "source": [ - "x = x + 2" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "7 4396779648\n" - ] - } - ], - "source": [ - "print(x, id(x))" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [], - "source": [ - "x = 5" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "y = 5" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "z = 5" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4396779584 4396779584 4396779584\n" - ] - } - ], - "source": [ - "print(id(x) , id(y) , id(z))" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x == y" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "x = 123456789" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "y = 123456789" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4434727856 4434728016\n" - ] - } - ], - "source": [ - "print(id(x) , id(y))" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x == y" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x is y" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [], - "source": [ - "x = 5" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "y = x" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "y == x" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "y is x" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "yes, it is.\n" - ] - } - ], - "source": [ - "if 10>4:\n", - " print('yes, it is.')" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n" - ] - } - ], - "source": [ - " print(5)" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "third elif\n" - ] - } - ], - "source": [ - "if 0.0:\n", - " print('if block')\n", - " if 5<10:\n", - " print('second if block')\n", - "elif '':\n", - " print('child if of 1St if')\n", - "elif False:\n", - " print('second elif')\n", - "elif 'wow':\n", - " print('third elif')\n", - "else:\n", - " print('else block')" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [], - "source": [ - "x = 5 if 20<10 else 'hello'" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "10%2" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [], - "source": [ - "y = 10" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10\n", - "11\n", - "12\n", - "13\n", - "14\n", - "15\n", - "16\n", - "17\n", - "18\n", - "19\n", - "outside of loop\n" - ] - } - ], - "source": [ - "while y < 20:\n", - " print(y)\n", - " y = y+1\n", - "print('outside of loop')" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "else of while\n", - "this is outside loop\n" - ] - } - ], - "source": [ - "while False:\n", - " print('while is true')\n", - " break\n", - "else:\n", - " print('else of while')\n", - "print('this is outside loop')" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "h\n", - "e\n", - "l\n", - "l\n", - "o\n" - ] - } - ], - "source": [ - "for i in 'hello':\n", - " print(i)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n" - ] - } - ], - "source": [ - "for i in range(5):\n", - " print(i)" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n", - "6\n", - "7\n", - "8\n", - "9\n" - ] - } - ], - "source": [ - "for i in range(5 , 10):\n", - " print(i)" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n", - "4\n", - "6\n", - "8\n" - ] - } - ], - "source": [ - "for i in range(2, 10, 2):\n", - " print(i)" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter a number6\n" - ] - } - ], - "source": [ - "x = input('Enter a number')" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "6\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], - "source": [ - "print(type(x))" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "first if\n", - "second if\n", - "third\n" - ] - } - ], - "source": [ - "if True:\n", - " print('first if')\n", - " if True:\n", - " print('second if')\n", - " if True:\n", - " print('third')\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.5rc1" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{"cells":[{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[{"data":{"text/plain":["\"It's a string\""]},"execution_count":1,"metadata":{},"output_type":"execute_result"}],"source":"\"It's a string\""},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[{"data":{"text/plain":["'It \"wow\" a string'"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":"'It \"wow\" a string'"},{"cell_type":"code","execution_count":11,"metadata":{},"outputs":[],"source":"t = 'hello this is long string ''python wow this is string'"},{"cell_type":"code","execution_count":12,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["hello this is long string python wow this is string\n"]}],"source":"print(t)"},{"cell_type":"code","execution_count":13,"metadata":{},"outputs":[{"data":{"text/plain":["'h'"]},"execution_count":13,"metadata":{},"output_type":"execute_result"}],"source":"'hello'[0]"},{"cell_type":"code","execution_count":15,"metadata":{},"outputs":[{"data":{"text/plain":["'hel'"]},"execution_count":15,"metadata":{},"output_type":"execute_result"}],"source":"'hello'[0:3]"},{"cell_type":"code","execution_count":18,"metadata":{},"outputs":[{"data":{"text/plain":["'hello'"]},"execution_count":18,"metadata":{},"output_type":"execute_result"}],"source":"'hello'[0:2] + 'hello'[2:len('hello')]"},{"cell_type":"code","execution_count":17,"metadata":{},"outputs":[{"data":{"text/plain":["5"]},"execution_count":17,"metadata":{},"output_type":"execute_result"}],"source":"len('hello')"},{"cell_type":"code","execution_count":19,"metadata":{},"outputs":[{"ename":"TypeError","evalue":"'str' object does not support item assignment","output_type":"error","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)","\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m'jello'\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'h'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment"]}],"source":"'jello'[0] = 'h'"},{"cell_type":"code","execution_count":20,"metadata":{},"outputs":[],"source":"x = 'hello'"},{"cell_type":"code","execution_count":21,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["hello 4434715624\n"]}],"source":"print(x , id(x))"},{"cell_type":"code","execution_count":22,"metadata":{},"outputs":[],"source":"x = 'hello' + 'python'"},{"cell_type":"code","execution_count":23,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["hellopython 4435060656\n"]}],"source":"print(x, id(x))"},{"cell_type":"code","execution_count":24,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["4396779584\n"]}],"source":"x = 5\nprint(id(5))"},{"cell_type":"code","execution_count":25,"metadata":{},"outputs":[],"source":"x = x + 2"},{"cell_type":"code","execution_count":27,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["7 4396779648\n"]}],"source":"print(x, id(x))"},{"cell_type":"code","execution_count":28,"metadata":{},"outputs":[],"source":"x = 5"},{"cell_type":"code","execution_count":29,"metadata":{},"outputs":[],"source":"y = 5"},{"cell_type":"code","execution_count":30,"metadata":{},"outputs":[],"source":"z = 5"},{"cell_type":"code","execution_count":31,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["4396779584 4396779584 4396779584\n"]}],"source":"print(id(x) , id(y) , id(z))"},{"cell_type":"code","execution_count":32,"metadata":{},"outputs":[{"data":{"text/plain":["True"]},"execution_count":32,"metadata":{},"output_type":"execute_result"}],"source":"x == y"},{"cell_type":"code","execution_count":33,"metadata":{},"outputs":[],"source":"x = 123456789"},{"cell_type":"code","execution_count":34,"metadata":{},"outputs":[],"source":"y = 123456789"},{"cell_type":"code","execution_count":35,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["4434727856 4434728016\n"]}],"source":"print(id(x) , id(y))"},{"cell_type":"code","execution_count":36,"metadata":{},"outputs":[{"data":{"text/plain":["True"]},"execution_count":36,"metadata":{},"output_type":"execute_result"}],"source":"x == y"},{"cell_type":"code","execution_count":37,"metadata":{},"outputs":[{"data":{"text/plain":["False"]},"execution_count":37,"metadata":{},"output_type":"execute_result"}],"source":"x is y"},{"cell_type":"code","execution_count":38,"metadata":{},"outputs":[],"source":"x = 5"},{"cell_type":"code","execution_count":39,"metadata":{},"outputs":[],"source":"y = x"},{"cell_type":"code","execution_count":40,"metadata":{},"outputs":[{"data":{"text/plain":["True"]},"execution_count":40,"metadata":{},"output_type":"execute_result"}],"source":"y == x"},{"cell_type":"code","execution_count":41,"metadata":{},"outputs":[{"data":{"text/plain":["True"]},"execution_count":41,"metadata":{},"output_type":"execute_result"}],"source":"y is x"},{"cell_type":"code","execution_count":42,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["yes, it is.\n"]}],"source":"if 10>4:\n print('yes, it is.')"},{"cell_type":"code","execution_count":43,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["5\n"]}],"source":"print(5)"},{"cell_type":"code","execution_count":45,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["third elif\n"]}],"source":"if 0.0:\n print('if block')\n if 5<10:\n print('second if block')\nelif '':\n print('child if of 1St if')\nelif False:\n print('second elif')\nelif 'wow':\n print('third elif')\nelse:\n print('else block')"},{"cell_type":"code","execution_count":46,"metadata":{},"outputs":[],"source":"x = 5 if 20<10 else 'hello'"},{"cell_type":"code","execution_count":47,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["hello\n"]}],"source":"print(x)"},{"cell_type":"code","execution_count":48,"metadata":{},"outputs":[{"data":{"text/plain":["0"]},"execution_count":48,"metadata":{},"output_type":"execute_result"}],"source":"10%2"},{"cell_type":"code","execution_count":53,"metadata":{},"outputs":[],"source":"y = 10"},{"cell_type":"code","execution_count":54,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["10\n","11\n","12\n","13\n","14\n","15\n","16\n","17\n","18\n","19\n","outside of loop\n"]}],"source":"while y < 20:\n print(y)\n y = y+1\nprint('outside of loop')"},{"cell_type":"code","execution_count":58,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["else of while\n","this is outside loop\n"]}],"source":"while False:\n print('while is true')\n break\nelse:\n print('else of while')\nprint('this is outside loop')"},{"cell_type":"code","execution_count":59,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["h\n","e\n","l\n","l\n","o\n"]}],"source":"for i in 'hello':\n print(i)"},{"cell_type":"code","execution_count":60,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["0\n","1\n","2\n","3\n","4\n"]}],"source":"for i in range(5):\n print(i)"},{"cell_type":"code","execution_count":61,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["5\n","6\n","7\n","8\n","9\n"]}],"source":"for i in range(5 , 10):\n print(i)"},{"cell_type":"code","execution_count":63,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["2\n","4\n","6\n","8\n"]}],"source":"for i in range(2, 10, 2):\n print(i)"},{"cell_type":"code","execution_count":64,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Enter a number6\n"]}],"source":"x = input('Enter a number')"},{"cell_type":"code","execution_count":65,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["6\n"]}],"source":"print(x)"},{"cell_type":"code","execution_count":66,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["\n"]}],"source":"print(type(x))"},{"cell_type":"code","execution_count":68,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["first if\n","second if\n","third\n"]}],"source":"if True:\n print('first if')\n if True:\n print('second if')\n if True:\n print('third')\n"},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":"def example(name):\n print(name)\n\nexample(\"john\")"}],"nbformat":4,"nbformat_minor":2,"metadata":{"language_info":{"name":"python","codemirror_mode":{"name":"ipython","version":3}},"orig_nbformat":2,"file_extension":".py","mimetype":"text/x-python","name":"python","npconvert_exporter":"python","pygments_lexer":"ipython3","version":3}} \ No newline at end of file