From ea2f5f09707ca885532df42af2868a7124af9d9b Mon Sep 17 00:00:00 2001 From: Abdelrahman Alkahwaji Date: Mon, 28 Oct 2019 15:22:09 +0900 Subject: [PATCH 01/10] Update 04-Lists.ipynb --- 00-Python Object and Data Structure Basics/04-Lists.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/00-Python Object and Data Structure Basics/04-Lists.ipynb b/00-Python Object and Data Structure Basics/04-Lists.ipynb index 332c404..98252e7 100644 --- a/00-Python Object and Data Structure Basics/04-Lists.ipynb +++ b/00-Python Object and Data Structure Basics/04-Lists.ipynb @@ -108,7 +108,7 @@ } ], "source": [ - "# Grab element at index 0\n", + "# Grab element at index 0 -- python is a zero index programming language\n", "my_list[0]" ] }, From 99eea87b2408308d483163f933f50eee1108b783 Mon Sep 17 00:00:00 2001 From: Abdelrahman Alkahwaji Date: Thu, 31 Oct 2019 17:53:34 +0900 Subject: [PATCH 02/10] Add more temperature --- 09-Built-in Functions/01-Map.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/09-Built-in Functions/01-Map.ipynb b/09-Built-in Functions/01-Map.ipynb index 6c08aab..2a96ad7 100644 --- a/09-Built-in Functions/01-Map.ipynb +++ b/09-Built-in Functions/01-Map.ipynb @@ -42,7 +42,7 @@ { "data": { "text/plain": [ - "[32.0, 72.5, 104.0, 212.0]" + "[32.0, 72.5, 104.0, 212.0,-14]" ] }, "execution_count": 2, From eb9e5d48690fac418ad3ff624a298c18d864ffa9 Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Mon, 25 Nov 2019 23:58:51 +0900 Subject: [PATCH 03/10] if - for loop - while loop --- ...01-Introduction to Python Statements.ipynb | 2 +- .../02-if, elif, and else Statements.ipynb | 67 ++- 02-Python Statements/03-for Loops.ipynb | 409 +++++++++++++++++- 02-Python Statements/04-while Loops.ipynb | 106 ++++- 4 files changed, 551 insertions(+), 33 deletions(-) diff --git a/02-Python Statements/01-Introduction to Python Statements.ipynb b/02-Python Statements/01-Introduction to Python Statements.ipynb index 4de998b..8e51e00 100644 --- a/02-Python Statements/01-Introduction to Python Statements.ipynb +++ b/02-Python Statements/01-Introduction to Python Statements.ipynb @@ -117,7 +117,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/02-Python Statements/02-if, elif, and else Statements.ipynb b/02-Python Statements/02-if, elif, and else Statements.ipynb index 262bd64..b1178d0 100644 --- a/02-Python Statements/02-if, elif, and else Statements.ipynb +++ b/02-Python Statements/02-if, elif, and else Statements.ipynb @@ -1,5 +1,16 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To control the flow of logic:\n", + " use\n", + " 1- if\n", + " 2- elif\n", + " 3- else" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -49,10 +60,49 @@ } ], "source": [ + "#if and elif: need condition but else doesn't need condition\n", "if True:\n", " print('It was true!')" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True!!\n" + ] + } + ], + "source": [ + "if 3>2:\n", + " print ('True!!')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am hungery .. Feed me!\n" + ] + } + ], + "source": [ + "hungery = True\n", + "\n", + "if hungery:\n", + " print ('I am hungery .. Feed me!')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -97,24 +147,27 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Welcome to the bank!\n" + "Welcome to the store!\n" ] } ], "source": [ - "loc = 'Bank'\n", + "# elif: check multiple conditions\n", + "loc = 'Store'\n", "\n", "if loc == 'Auto Shop':\n", " print('Welcome to the Auto Shop!')\n", "elif loc == 'Bank':\n", " print('Welcome to the bank!')\n", + "elif loc =='Store':\n", + " print('Welcome to the store!')\n", "else:\n", " print('Where are you?')" ] @@ -152,19 +205,19 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Welcome George!\n" + "Welcome, what's your name?\n" ] } ], "source": [ - "person = 'George'\n", + "person = 'Abdel'\n", "\n", "if person == 'Sammy':\n", " print('Welcome Sammy!')\n", @@ -200,7 +253,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/02-Python Statements/03-for Loops.ipynb b/02-Python Statements/03-for Loops.ipynb index 61f54fe..f70a6a0 100644 --- a/02-Python Statements/03-for Loops.ipynb +++ b/02-Python Statements/03-for Loops.ipynb @@ -6,7 +6,7 @@ "source": [ "# for Loops\n", "\n", - "A for loop acts as an iterator in Python; it goes through items that are in a *sequence* or any other iterable item. Objects that we've learned about that we can iterate over include strings, lists, tuples, and even built-in iterables for dictionaries, such as keys or values.\n", + "A for loop acts as an iterator in Python; it goes through items that are in a *sequence* or any other iterable item. Objects that we've learned about that we can iterate over include strings, lists, tuples, and even built-in iterables for dictionaries, such as keys or values.\n", "\n", "We've already seen the for statement a little bit in past lectures but now let's formalize our understanding.\n", "\n", @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -66,6 +66,281 @@ " print(num)" ] }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n" + ] + } + ], + "source": [ + "for i in list1: #your can use _ as item name\n", + " print ('Hello, Alkahwaji!!')" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n", + "Hello, Alkahwaji!!\n" + ] + } + ], + "source": [ + "for _ in list1: #your can use _ as item name\n", + " print ('Hello, Alkahwaji!!')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "6\n", + "8\n", + "10\n" + ] + } + ], + "source": [ + "#print the even number from list1\n", + "for num in list1:\n", + " #check for even\n", + " if num %2==0:\n", + " print (num)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Odd Number!!:1\n", + "2\n", + "Odd Number!!:3\n", + "4\n", + "Odd Number!!:5\n", + "6\n", + "Odd Number!!:7\n", + "8\n", + "Odd Number!!:9\n", + "10\n" + ] + } + ], + "source": [ + "#print the even number from list1 - with else statement\n", + "for num in list1:\n", + " #check for even\n", + " if num %2==0:\n", + " print (num)\n", + " else:\n", + " print ('Odd Number!!:%s'%num)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Odd Number!!:1\n", + "2\n", + "Odd Number!!:3\n", + "4\n", + "Odd Number!!:5\n", + "6\n", + "Odd Number!!:7\n", + "8\n", + "Odd Number!!:9\n", + "10\n" + ] + } + ], + "source": [ + "#print the even number from list1 - with else statement\n", + "for num in list1:\n", + " #check for even\n", + " if num %2==0:\n", + " print (num)\n", + " else:\n", + " print (f'Odd Number!!:{num}')" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "3\n", + "6\n", + "10\n", + "15\n", + "21\n", + "28\n", + "36\n", + "45\n", + "55\n", + "The sum of list is 55\n" + ] + } + ], + "source": [ + "list_sum = 0\n", + "\n", + "for i in list1:\n", + " list_sum+=i\n", + " print (list_sum)\n", + " \n", + "print (f\"The sum of list is {list_sum}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\n", + "e\n", + "l\n", + "l\n", + "o\n", + " \n", + "w\n", + "o\n", + "r\n", + "l\n", + "d\n" + ] + } + ], + "source": [ + "mystr = 'hello world'\n", + "\n", + "for letter in mystr:\n", + " print (letter)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h\n", + "e\n", + "l\n", + "l\n", + "o\n", + " \n", + "w\n", + "o\n", + "r\n", + "l\n", + "d\n" + ] + } + ], + "source": [ + "for letter in 'hello world':\n", + " print (letter)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "tup = (1,2,3)\n", + "for item in tup:\n", + " print (item)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -382,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -391,7 +666,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -411,7 +686,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -430,6 +705,26 @@ " print(t1)" ] }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "6\n", + "10\n" + ] + } + ], + "source": [ + "for a,b in list2: #for 2 or more tuples\n", + " print (a)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -446,7 +741,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -455,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -469,10 +764,106 @@ } ], "source": [ + "#Iterate through dictionary :: OUTPUT IS KEY\n", "for item in d:\n", " print(item)" ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('k1', 1)\n", + "('k2', 2)\n", + "('k3', 3)\n" + ] + } + ], + "source": [ + "#Iterate through items\n", + "for item in d.items():\n", + " print (item) #The output is tuple" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "k1\n", + "1\n", + "k2\n", + "2\n", + "k3\n", + "3\n" + ] + } + ], + "source": [ + "#Iterate through items\n", + "for k,v in d.items():\n", + " print (k)\n", + " print(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "#Iterate through values\n", + "for val in d.values():\n", + " print(val)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "k1\n", + "k2\n", + "k3\n" + ] + } + ], + "source": [ + "#Iterate through keys\n", + "for kk in d.keys():\n", + " print(kk)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -619,7 +1010,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/02-Python Statements/04-while Loops.ipynb b/02-Python Statements/04-while Loops.ipynb index f8ff559..370e265 100644 --- a/02-Python Statements/04-while Loops.ipynb +++ b/02-Python Statements/04-while Loops.ipynb @@ -12,7 +12,7 @@ "\n", "The general format of a while loop is:\n", "\n", - " while test:\n", + " while test (Boolean condition):\n", " code statements\n", " else:\n", " final code statements\n", @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -87,30 +87,20 @@ " x is still less than 10, adding 1 to x\n", "x is currently: 4\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 5\n", - " x is still less than 10, adding 1 to x\n", - "x is currently: 6\n", - " x is still less than 10, adding 1 to x\n", - "x is currently: 7\n", - " x is still less than 10, adding 1 to x\n", - "x is currently: 8\n", - " x is still less than 10, adding 1 to x\n", - "x is currently: 9\n", - " x is still less than 10, adding 1 to x\n", - "All Done!\n" + "All Done! -- X is not less than 5\n" ] } ], "source": [ "x = 0\n", "\n", - "while x < 10:\n", + "while x < 5:\n", " print('x is currently: ',x)\n", " print(' x is still less than 10, adding 1 to x')\n", " x+=1\n", " \n", "else:\n", - " print('All Done!')" + " print('All Done! -- X is not less than 5')" ] }, { @@ -141,6 +131,90 @@ "Let's go ahead and look at some examples!" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "x = [1,2,3]\n", + "\n", + "for item in x:\n", + " pass #as a filler -- pass: do nothing" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "S\n", + "m\n", + "m\n", + "y\n" + ] + } + ], + "source": [ + "mystr = 'Sammy'\n", + "for letter in mystr:\n", + " if letter =='a':\n", + " continue # the top of the closest enclosing loop.\n", + " #the letter in mystr loop\n", + " print (letter)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "S\n", + "a\n" + ] + } + ], + "source": [ + "mystr = 'Sammy'\n", + "for letter in mystr:\n", + " if letter =='m':\n", + " break # the current closest enclosing loop.\n", + " #the letter == a loop\n", + " print (letter)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n" + ] + } + ], + "source": [ + "x = 0\n", + "while x <5:\n", + " if x ==3:\n", + " break\n", + " print (x)\n", + " x+=1" + ] + }, { "cell_type": "code", "execution_count": 3, @@ -288,7 +362,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, From 8e07b2dccf4a43f6b063bf9d9ddef1b43c1c74b1 Mon Sep 17 00:00:00 2001 From: Abdelrahman Alkahwaji Date: Tue, 26 Nov 2019 00:20:16 +0900 Subject: [PATCH 04/10] Update README.md --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index de18f6a..8453a77 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ # Complete-Python-3-Bootcamp -Course Files for Complete Python 3 Bootcamp Course on Udemy - - -Get it now for 95% off with the link: -https://www.udemy.com/complete-python-bootcamp/?couponCode=COMPLETE_GITHUB +Course Files for Complete Python 3 Bootcamp Course Thanks! From 099ee658b9ea1863602b96859b0b65059c321c41 Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Tue, 26 Nov 2019 00:48:23 +0900 Subject: [PATCH 05/10] Operations --- .../05-Useful-Operators.ipynb | 268 +++++++++++++++++- 1 file changed, 255 insertions(+), 13 deletions(-) diff --git a/02-Python Statements/05-Useful-Operators.ipynb b/02-Python Statements/05-Useful-Operators.ipynb index 632406a..31131ee 100644 --- a/02-Python Statements/05-Useful-Operators.ipynb +++ b/02-Python Statements/05-Useful-Operators.ipynb @@ -38,6 +38,58 @@ "range(0,11)" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ], + "source": [ + "for num in range(10):\n", + " print (num)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "6\n", + "9\n", + "12\n", + "15\n", + "18\n" + ] + } + ], + "source": [ + "for i in range(3,20,3): #start, stop, step\n", + " print (i)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -141,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -195,6 +247,78 @@ " print(\"At index {} the letter is {}\".format(i,letter))" ] }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0, 'a')\n", + "(1, 'b')\n", + "(2, 'c')\n", + "(3, 'd')\n", + "(4, 'e')\n", + "(5, 'f')\n" + ] + } + ], + "source": [ + "#output is tuple\n", + "word = 'abcdef'\n", + "\n", + "for item in enumerate(word):\n", + " print (item)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "a\n", + "\n", + "\n", + "1\n", + "b\n", + "\n", + "\n", + "2\n", + "c\n", + "\n", + "\n", + "3\n", + "d\n", + "\n", + "\n", + "4\n", + "e\n", + "\n", + "\n", + "5\n", + "f\n", + "\n", + "\n" + ] + } + ], + "source": [ + "#output is tuple\n", + "word = 'abcdef'\n", + "\n", + "for index, letter in enumerate(word):\n", + " print (index)\n", + " print(letter)\n", + " print ('\\n')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -261,6 +385,7 @@ ], "source": [ "# This one is also a generator! We will explain this later, but for now let's transform it to a list\n", + "#The opposite of enumerate -- To the shortest list\n", "zip(mylist1,mylist2)" ] }, @@ -362,6 +487,74 @@ "'x' in [1,2,3]" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'a' in 'a world '" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'mykey' in {'mykey':100}" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d = {'yourkey':356}\n", + "310 in d.keys()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -433,10 +626,8 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": { - "collapsed": true - }, + "execution_count": 22, + "metadata": {}, "outputs": [], "source": [ "from random import shuffle" @@ -444,10 +635,17 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "mylist = [10,20,30,40,100]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, "outputs": [], "source": [ "# This shuffles the list \"in-place\" meaning it won't return\n", @@ -457,16 +655,16 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[40, 10, 100, 30, 20]" + "[40, 10, 20, 100, 30]" ] }, - "execution_count": 36, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -561,6 +759,50 @@ "source": [ "input('Enter Something into this box: ')" ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ente a number here: 10\n" + ] + } + ], + "source": [ + "result = input('Ente a number here: ')" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'10'" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -579,7 +821,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.1" + "version": "3.7.3" } }, "nbformat": 4, From 1d82d9c21a4885db6bb18e5984e1b7a50c13a7cb Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Tue, 26 Nov 2019 01:09:24 +0900 Subject: [PATCH 06/10] List comprehension --- .../06-List Comprehensions.ipynb | 186 +++++++++++++++++- 1 file changed, 184 insertions(+), 2 deletions(-) diff --git a/02-Python Statements/06-List Comprehensions.ipynb b/02-Python Statements/06-List Comprehensions.ipynb index 256271b..40d1dd2 100644 --- a/02-Python Statements/06-List Comprehensions.ipynb +++ b/02-Python Statements/06-List Comprehensions.ipynb @@ -14,6 +14,76 @@ "## Example 1" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "mystr = 'hello'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "mylist = []\n", + "\n", + "for letter in mystr:\n", + " mylist.append(letter)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['h', 'e', 'l', 'l', 'o']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mylist" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "mylist1 = [letter for letter in 'hello_world']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['h', 'e', 'l', 'l', 'o', '_', 'w', 'o', 'r', 'l', 'd']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mylist1" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -45,6 +115,27 @@ "lst" ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mylist3 = [x for x in range(0,11)]\n", + "mylist3" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -123,6 +214,35 @@ "lst" ] }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "even = [x if x%2 == 0 else 'ODD' for x in range (0,14)]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 'ODD', 2, 'ODD', 4, 'ODD', 6, 'ODD', 8, 'ODD', 10, 'ODD', 12, 'ODD']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "even" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -148,7 +268,7 @@ } ], "source": [ - "# Convert Celsius to Fahrenheit\n", + "# Convert Celsius list to Fahrenheit list\n", "celsius = [0,10,20.1,34.5]\n", "\n", "fahrenheit = [((9/5)*temp + 32) for temp in celsius ]\n", @@ -164,6 +284,68 @@ "We can also perform nested list comprehensions, for example:" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "mylist4 = []\n", + "\n", + "for x in [2,4,6]:\n", + " for y in [100,200,300]:\n", + " mylist4.append(x*y)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[200, 400, 600, 400, 800, 1200, 600, 1200, 1800]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mylist4" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "list5 = [x*y for x in [2,4,6] for y in [100,200,300]]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[200, 400, 600, 400, 800, 1200, 600, 1200, 1800]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list5" + ] + }, { "cell_type": "code", "execution_count": 8, @@ -209,7 +391,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, From b24a2c6ff0bd254b9733b5348a8c4f64d887ad13 Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Tue, 26 Nov 2019 02:02:20 +0900 Subject: [PATCH 07/10] Solution of the test --- .../07-Statements Assessment Test.ipynb | 256 ++++++++++++++++-- 1 file changed, 235 insertions(+), 21 deletions(-) diff --git a/02-Python Statements/07-Statements Assessment Test.ipynb b/02-Python Statements/07-Statements Assessment Test.ipynb index b9e5454..3514456 100644 --- a/02-Python Statements/07-Statements Assessment Test.ipynb +++ b/02-Python Statements/07-Statements Assessment Test.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -29,13 +29,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Print only the word', ' that ', 'tart with ', ' in thi', ' ', 'entence']" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "st.split('s')" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "start\n", + "s\n", + "sentence\n" + ] + } + ], "source": [ - "#Code here" + "for i in st.split():\n", + " if i[0].lower() == 's': #if capital will be small fit 's'\n", + " print (i)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -46,11 +85,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n", + "6\n", + "8\n", + "10\n" + ] + } + ], "source": [ - "#Code Here" + "list(range(0,11,2))\n", + "for i in range (0,11,2):\n", + " print (i)" ] }, { @@ -63,12 +117,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#Code in this cell\n", - "[]" + "[x for x in range(0,51) if x%3==0]" ] }, { @@ -90,11 +155,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "only is even!\n", + "that is even!\n", + "with is even!\n", + "in is even!\n", + "this is even!\n", + "sentence is even!\n" + ] + } + ], "source": [ - "#Code in this cell" + "for i in st.split():\n", + " if len(i) %2 ==0:\n", + " print (i,\" is even!\")" ] }, { @@ -107,11 +187,126 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "Fizz\n", + "4\n", + "Buzz\n", + "Fizz\n", + "7\n", + "8\n", + "Fizz\n", + "Buzz\n", + "11\n", + "Fizz\n", + "13\n", + "14\n", + "FizzBuzz\n", + "16\n", + "17\n", + "Fizz\n", + "19\n", + "Buzz\n", + "Fizz\n", + "22\n", + "23\n", + "Fizz\n", + "Buzz\n", + "26\n", + "Fizz\n", + "28\n", + "29\n", + "FizzBuzz\n", + "31\n", + "32\n", + "Fizz\n", + "34\n", + "Buzz\n", + "Fizz\n", + "37\n", + "38\n", + "Fizz\n", + "Buzz\n", + "41\n", + "Fizz\n", + "43\n", + "44\n", + "FizzBuzz\n", + "46\n", + "47\n", + "Fizz\n", + "49\n", + "Buzz\n", + "Fizz\n", + "52\n", + "53\n", + "Fizz\n", + "Buzz\n", + "56\n", + "Fizz\n", + "58\n", + "59\n", + "FizzBuzz\n", + "61\n", + "62\n", + "Fizz\n", + "64\n", + "Buzz\n", + "Fizz\n", + "67\n", + "68\n", + "Fizz\n", + "Buzz\n", + "71\n", + "Fizz\n", + "73\n", + "74\n", + "FizzBuzz\n", + "76\n", + "77\n", + "Fizz\n", + "79\n", + "Buzz\n", + "Fizz\n", + "82\n", + "83\n", + "Fizz\n", + "Buzz\n", + "86\n", + "Fizz\n", + "88\n", + "89\n", + "FizzBuzz\n", + "91\n", + "92\n", + "Fizz\n", + "94\n", + "Buzz\n", + "Fizz\n", + "97\n", + "98\n", + "Fizz\n", + "Buzz\n" + ] + } + ], "source": [ - "#Code in this cell" + "for i in range (1,101):\n", + " if i %3 == 0 and i%5 ==0:\n", + " print ('FizzBuzz')\n", + " elif i %5 == 0:\n", + " print ('Buzz')\n", + " elif i%3 ==0:\n", + " print ('Fizz')\n", + " else:\n", + " print (i)" ] }, { @@ -124,7 +319,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -133,11 +328,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['C', 'a', 'l', 'o', 't', 'f', 'l', 'o', 'e', 'w', 'i', 't', 's']" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#Code in this cell" + "first_let = [x[0] for x in st.split()cc]\n", + "first_let" ] }, { @@ -146,6 +353,13 @@ "source": [ "### Great Job!" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -164,7 +378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, From 53d40e33ec2707c2ebe8c33f6779e77fc93cb26e Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Tue, 17 Dec 2019 23:52:05 +0900 Subject: [PATCH 08/10] For loop --- 02-Python Statements/03-for Loops.ipynb | 60 ++++++++++--------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/02-Python Statements/03-for Loops.ipynb b/02-Python Statements/03-for Loops.ipynb index f70a6a0..c3c809e 100644 --- a/02-Python Statements/03-for Loops.ipynb +++ b/02-Python Statements/03-for Loops.ipynb @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 4, "metadata": { "scrolled": true }, @@ -77,49 +77,49 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n" + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n" ] } ], "source": [ "for i in list1: #your can use _ as item name\n", - " print ('Hello, Alkahwaji!!')" + " print ('Hello, Alkahwaji!')" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n", - "Hello, Alkahwaji!!\n" + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n", + "Hello, Alkahwaji!\n" ] } ], "source": [ "for _ in list1: #your can use _ as item name\n", - " print ('Hello, Alkahwaji!!')" + " print ('Hello, Alkahwaji!')" ] }, { @@ -999,18 +999,6 @@ "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.7.3" } }, "nbformat": 4, From f6c62de566f889f2d69a62d459acce5761a55401 Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Tue, 17 Dec 2019 23:58:54 +0900 Subject: [PATCH 09/10] Function --- 03-Methods and Functions/02-Functions.ipynb | 253 +++++++++++++++++++- 1 file changed, 247 insertions(+), 6 deletions(-) diff --git a/03-Methods and Functions/02-Functions.ipynb b/03-Methods and Functions/02-Functions.ipynb index 1e9243d..14ef60e 100644 --- a/03-Methods and Functions/02-Functions.ipynb +++ b/03-Methods and Functions/02-Functions.ipynb @@ -28,6 +28,16 @@ "Let's see how to build out a function's syntax in Python. It has the following form:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#return : assign the value of the function into the new variable \n", + "#" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -68,14 +78,62 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def say_hello():\n", + " '''\n", + " DOCSTRING: Information about the function\n", + " Input: NO input\n", + " OUTPUT: Hello\n", + " '''\n", " print('hello')" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "say_hello" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function say_hello in module __main__:\n", + "\n", + "say_hello()\n", + " DOCSTRING: Information about the function\n", + " Input: NO input\n", + " OUTPUT: Hello\n", + "\n" + ] + } + ], + "source": [ + "help(say_hello)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -85,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -110,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -120,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -135,6 +193,36 @@ "greeting('Jose')" ] }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "#set a default\n", + "def say_hello1(name='NAME'):\n", + " print ('hello %s' %name)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello NAME\n", + "hello Ahmed\n" + ] + } + ], + "source": [ + "say_hello1()#default in case of not providing the argument\n", + "say_hello1('Ahmed')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -145,6 +233,40 @@ "### Example 3: Addition function" ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello mana\n" + ] + } + ], + "source": [ + "a = say_hello1('mana')" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [ + "print(a) #No data will be saved in the variable COZ we used print not return in the function" + ] + }, { "cell_type": "code", "execution_count": 6, @@ -251,7 +373,126 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "def dog_check(my_string):\n", + " if 'dog' in my_string.lower():\n", + " return True\n", + " else: \n", + " return False\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dog_check('This is my dog')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dog_check('Dog ran away')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'dog' in 'This is my dog'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### PIG LATIN\n", + "* If word starts with a vowel, add 'ay' to end\n", + "* If word does not start with a vowel, put first letter at the end, then add 'ay' \n", + "* word >>> ordway\n", + "* apply>> appleay" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "def pig_latin(word):\n", + " if word[0].lower() in 'aeiou':\n", + " pig_word = word +'ay'\n", + " else:\n", + " pig_word = word[1:] + word[0]+ 'ay' \n", + " return pig_word" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'pplemay'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pig_latin('mpple')" + ] + }, + { + "cell_type": "code", + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -383,7 +624,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, From babb3b3515be5dbb47b68db14561b8123f85e67a Mon Sep 17 00:00:00 2001 From: Alkahwaji Date: Sun, 22 Dec 2019 02:57:38 +0900 Subject: [PATCH 10/10] modifications --- .../02-if, elif, and else Statements.ipynb | 49 ++++ 02-Python Statements/03-for Loops.ipynb | 93 +++++-- 02-Python Statements/04-while Loops.ipynb | 27 +- .../05-Useful-Operators.ipynb | 70 ++++- .../06-List Comprehensions.ipynb | 81 +++++- .../01-Methods-checkpoint.ipynb | 17 +- .../02-Functions-checkpoint.ipynb | 253 +++++++++++++++++- ...nction Practice Exercises-checkpoint.ipynb | 2 +- .../07-args and kwargs-checkpoint.ipynb | 127 ++++++++- 03-Methods and Functions/01-Methods.ipynb | 17 +- .../03-Function Practice Exercises.ipynb | 2 +- .../07-args and kwargs.ipynb | 127 ++++++++- ...Advanced Object Oriented Programming.ipynb | 2 +- 13 files changed, 785 insertions(+), 82 deletions(-) diff --git a/02-Python Statements/02-if, elif, and else Statements.ipynb b/02-Python Statements/02-if, elif, and else Statements.ipynb index b1178d0..f64261d 100644 --- a/02-Python Statements/02-if, elif, and else Statements.ipynb +++ b/02-Python Statements/02-if, elif, and else Statements.ipynb @@ -61,10 +61,37 @@ ], "source": [ "#if and elif: need condition but else doesn't need condition\n", + "#if -else-elif used to control flow\n", + "#if the dog is hunger: go to feed\n", "if True:\n", " print('It was true!')" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It's true!!\n" + ] + } + ], + "source": [ + "if True:\n", + " print (\"It's true!!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": 1, @@ -103,6 +130,28 @@ " print ('I am hungery .. Feed me!')" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am not hungery\n" + ] + } + ], + "source": [ + "hungery = False\n", + "\n", + "if hungery:\n", + " print ('Feed me!!')\n", + "else:\n", + " print('I am not hungery')" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/02-Python Statements/03-for Loops.ipynb b/02-Python Statements/03-for Loops.ipynb index c3c809e..e2aa410 100644 --- a/02-Python Statements/03-for Loops.ipynb +++ b/02-Python Statements/03-for Loops.ipynb @@ -36,6 +36,7 @@ "outputs": [], "source": [ "# We'll learn how to automate this sort of list in the next lecture\n", + "\n", "list1 = [1,2,3,4,5,6,7,8,9,10]" ] }, @@ -62,6 +63,7 @@ } ], "source": [ + "#iterate: character in string - item in a list - key in a dictionary \n", "for num in list1:\n", " print(num)" ] @@ -183,22 +185,22 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Odd Number!!:1\n", + "Odd Number!!: 1\n", "2\n", - "Odd Number!!:3\n", + "Odd Number!!: 3\n", "4\n", - "Odd Number!!:5\n", + "Odd Number!!: 5\n", "6\n", - "Odd Number!!:7\n", + "Odd Number!!: 7\n", "8\n", - "Odd Number!!:9\n", + "Odd Number!!: 9\n", "10\n" ] } @@ -210,7 +212,7 @@ " if num %2==0:\n", " print (num)\n", " else:\n", - " print (f'Odd Number!!:{num}')" + " print (f'Odd Number!!: {num}')" ] }, { @@ -329,10 +331,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cool!!\n", + "Cool!!\n", + "Cool!!\n", + "Cool!!\n", + "Cool!!\n" + ] + } + ], + "source": [ + "#_ as a place holder -- we don't need a variable\n", + "for _ in range(5):\n", + " print('Cool!!')" + ] }, { "cell_type": "code", @@ -657,16 +675,36 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ - "list2 = [(2,4),(6,8),(10,12)]" + "list2 = [(2,4),(6,8),(10,12),(100,101)]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(list2)" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -675,7 +713,8 @@ "text": [ "(2, 4)\n", "(6, 8)\n", - "(10, 12)\n" + "(10, 12)\n", + "(100, 101)\n" ] } ], @@ -686,7 +725,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -694,15 +733,21 @@ "output_type": "stream", "text": [ "2\n", + "4\n", "6\n", - "10\n" + "8\n", + "10\n", + "12\n", + "100\n", + "101\n" ] } ], "source": [ - "# Now with unpacking!\n", + "# Now with unpacking! remove brackets t1,t2 instead of (t1,t2)\n", "for (t1,t2) in list2:\n", - " print(t1)" + " print(t1)\n", + " print(t2)" ] }, { @@ -999,6 +1044,18 @@ "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.7.3" } }, "nbformat": 4, diff --git a/02-Python Statements/04-while Loops.ipynb b/02-Python Statements/04-while Loops.ipynb index 370e265..ebfcca8 100644 --- a/02-Python Statements/04-while Loops.ipynb +++ b/02-Python Statements/04-while Loops.ipynb @@ -8,7 +8,7 @@ "source": [ "# while Loops\n", "\n", - "The while statement in Python is one of most general ways to perform iteration. A while statement will repeatedly execute a single statement or group of statements as long as the condition is true. The reason it is called a 'loop' is because the code statements are looped through over and over again until the condition is no longer met.\n", + "The while statement in Python is one of most general ways to perform iteration. A while statement will repeatedly execute a single statement or group of statements as long as the condition is true . The reason it is called a 'loop' is because the code statements are looped through over and over again until the condition is no longer met.\n", "\n", "The general format of a while loop is:\n", "\n", @@ -22,32 +22,32 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "x is currently: 0\n", + "x is currently: 0\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 1\n", + "x is currently: 1\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 2\n", + "x is currently: 2\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 3\n", + "x is currently: 3\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 4\n", + "x is currently: 4\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 5\n", + "x is currently: 5\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 6\n", + "x is currently: 6\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 7\n", + "x is currently: 7\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 8\n", + "x is currently: 8\n", " x is still less than 10, adding 1 to x\n", - "x is currently: 9\n", + "x is currently: 9\n", " x is still less than 10, adding 1 to x\n" ] } @@ -56,7 +56,7 @@ "x = 0\n", "\n", "while x < 10:\n", - " print('x is currently: ',x)\n", + " print(f'x is currently: {x}')\n", " print(' x is still less than 10, adding 1 to x')\n", " x+=1" ] @@ -92,6 +92,7 @@ } ], "source": [ + "#We can use else with while.\n", "x = 0\n", "\n", "while x < 5:\n", diff --git a/02-Python Statements/05-Useful-Operators.ipynb b/02-Python Statements/05-Useful-Operators.ipynb index 31131ee..ae7bd37 100644 --- a/02-Python Statements/05-Useful-Operators.ipynb +++ b/02-Python Statements/05-Useful-Operators.ipynb @@ -357,10 +357,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": true - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "mylist1 = [1,2,3,4,5]\n", @@ -418,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -529,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -538,7 +536,7 @@ "False" ] }, - "execution_count": 21, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -550,10 +548,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "356 in d.values()" + ] }, { "cell_type": "markdown", @@ -762,7 +773,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -779,7 +790,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -788,7 +799,7 @@ "'10'" ] }, - "execution_count": 33, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -797,6 +808,39 @@ "result" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "int_res = int(result)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], + "source": [ + "print(int_res)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/02-Python Statements/06-List Comprehensions.ipynb b/02-Python Statements/06-List Comprehensions.ipynb index 40d1dd2..bc52192 100644 --- a/02-Python Statements/06-List Comprehensions.ipynb +++ b/02-Python Statements/06-List Comprehensions.ipynb @@ -57,16 +57,18 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ + "#[item for item in the iterate list or object]\n", + "#if you want to form operation form it in the first item\n", "mylist1 = [letter for letter in 'hello_world']" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -75,7 +77,7 @@ "['h', 'e', 'l', 'l', 'o', '_', 'w', 'o', 'r', 'l', 'd']" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -86,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -96,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -105,7 +107,7 @@ "['w', 'o', 'r', 'd']" ] }, - "execution_count": 2, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -115,6 +117,35 @@ "lst" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "num = [n for n in range(5)]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 4]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "num" + ] + }, { "cell_type": "code", "execution_count": 6, @@ -148,17 +179,17 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "# Square numbers in range and turn into list\n", + "# Square numbers in range and turn into list >> form operations in the first item\n", "lst = [x**2 for x in range(0,11)]" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -167,7 +198,7 @@ "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" ] }, - "execution_count": 4, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -190,7 +221,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Check for even numbers in a range\n", + "# Check for even numbers in a range \n", "lst = [x for x in range(11) if x % 2 == 0]" ] }, @@ -243,6 +274,34 @@ "even" ] }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "ll = [xx if xx%2==0 else 'This is an ODD number!!' for xx in range(11)]" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 'This is an ODD number!!', 2, 'This is an ODD number!!', 4, 'This is an ODD number!!', 6, 'This is an ODD number!!', 8, 'This is an ODD number!!', 10]\n" + ] + } + ], + "source": [ + "print(ll)" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/03-Methods and Functions/.ipynb_checkpoints/01-Methods-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/01-Methods-checkpoint.ipynb index fde90b4..623bfa8 100644 --- a/03-Methods and Functions/.ipynb_checkpoints/01-Methods-checkpoint.ipynb +++ b/03-Methods and Functions/.ipynb_checkpoints/01-Methods-checkpoint.ipynb @@ -21,7 +21,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#Method is a function in an object\n", + "#Ways to know methods:\n", + "#1- help function .. Tab in jupyter\n", + "#2- shift +tab in jupyter\n", + "#3- python standard library" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -170,7 +183,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/.ipynb_checkpoints/02-Functions-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/02-Functions-checkpoint.ipynb index 1e9243d..14ef60e 100644 --- a/03-Methods and Functions/.ipynb_checkpoints/02-Functions-checkpoint.ipynb +++ b/03-Methods and Functions/.ipynb_checkpoints/02-Functions-checkpoint.ipynb @@ -28,6 +28,16 @@ "Let's see how to build out a function's syntax in Python. It has the following form:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#return : assign the value of the function into the new variable \n", + "#" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -68,14 +78,62 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def say_hello():\n", + " '''\n", + " DOCSTRING: Information about the function\n", + " Input: NO input\n", + " OUTPUT: Hello\n", + " '''\n", " print('hello')" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "say_hello" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function say_hello in module __main__:\n", + "\n", + "say_hello()\n", + " DOCSTRING: Information about the function\n", + " Input: NO input\n", + " OUTPUT: Hello\n", + "\n" + ] + } + ], + "source": [ + "help(say_hello)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -85,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -110,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -120,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -135,6 +193,36 @@ "greeting('Jose')" ] }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "#set a default\n", + "def say_hello1(name='NAME'):\n", + " print ('hello %s' %name)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello NAME\n", + "hello Ahmed\n" + ] + } + ], + "source": [ + "say_hello1()#default in case of not providing the argument\n", + "say_hello1('Ahmed')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -145,6 +233,40 @@ "### Example 3: Addition function" ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello mana\n" + ] + } + ], + "source": [ + "a = say_hello1('mana')" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [ + "print(a) #No data will be saved in the variable COZ we used print not return in the function" + ] + }, { "cell_type": "code", "execution_count": 6, @@ -251,7 +373,126 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "def dog_check(my_string):\n", + " if 'dog' in my_string.lower():\n", + " return True\n", + " else: \n", + " return False\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dog_check('This is my dog')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dog_check('Dog ran away')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'dog' in 'This is my dog'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### PIG LATIN\n", + "* If word starts with a vowel, add 'ay' to end\n", + "* If word does not start with a vowel, put first letter at the end, then add 'ay' \n", + "* word >>> ordway\n", + "* apply>> appleay" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "def pig_latin(word):\n", + " if word[0].lower() in 'aeiou':\n", + " pig_word = word +'ay'\n", + " else:\n", + " pig_word = word[1:] + word[0]+ 'ay' \n", + " return pig_word" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'pplemay'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pig_latin('mpple')" + ] + }, + { + "cell_type": "code", + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -383,7 +624,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb index cb906db..a0cee6b 100644 --- a/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb +++ b/03-Methods and Functions/.ipynb_checkpoints/03-Function Practice Exercises-checkpoint.ipynb @@ -707,7 +707,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/.ipynb_checkpoints/07-args and kwargs-checkpoint.ipynb b/03-Methods and Functions/.ipynb_checkpoints/07-args and kwargs-checkpoint.ipynb index 47fa02a..3372204 100644 --- a/03-Methods and Functions/.ipynb_checkpoints/07-args and kwargs-checkpoint.ipynb +++ b/03-Methods and Functions/.ipynb_checkpoints/07-args and kwargs-checkpoint.ipynb @@ -77,23 +77,33 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(40, 60, 20)\n" + ] + }, { "data": { "text/plain": [ "6.0" ] }, - "execution_count": 3, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "#pass as many parameters or arguments as I want\n", "def myfunc(*args):\n", + " print (args) #tuple\n", " return sum(args)*.05\n", + " \n", "\n", "myfunc(40,60,20)" ] @@ -109,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -118,18 +128,49 @@ "6.0" ] }, - "execution_count": 4, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "def myfunc(*spam):\n", - " return sum(spam)*.05\n", + "# We can use any keywards by using * before it\n", + "def myfunc(*mana):\n", + " return sum(mana)*.05\n", "\n", "myfunc(40,60,20)" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def p_item(*zizo):\n", + " for i in zizo:\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mana\n", + "zizo\n", + "migo\n" + ] + } + ], + "source": [ + "p_item('mana','zizo','migo')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -179,6 +220,39 @@ "myfunc()" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "#** as dictionary \n", + "def vfruit (**kwargs):\n", + " print (kwargs)\n", + " if 'fruit' in kwargs:\n", + " print('my fruit of choice is {}'.format(kwargs['fruit']))\n", + " else:\n", + " print('I did not find any fruit here')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'ffruit': 'mango', 'vegitable': 'lettuce'}\n", + "I did not find any fruit here\n" + ] + } + ], + "source": [ + "vfruit(fruit='mango',vegitable='lettuce')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -246,6 +320,45 @@ "\n", "That's it! Now you should understand how `*args` and `**kwargs` provide the flexibilty to work with arbitrary numbers of arguments!" ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "def myfunc(*args,**kwargs):\n", + " print (args) #tuple\n", + " print(kwargs) #dictionary\n", + " print ('I would like {} {}'.format(args[0],kwargs['food']))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(10, 20, 30)\n", + "{'fruit': 'orange', 'food': 'eggs', 'animals': 'dog'}\n", + "I would like 10 eggs\n" + ] + } + ], + "source": [ + "#we have to be in the same order args firstS>> then kwargs\n", + "myfunc(10,20,30,fruit='orange',food='eggs',animals='dog')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -264,7 +377,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/01-Methods.ipynb b/03-Methods and Functions/01-Methods.ipynb index fde90b4..623bfa8 100644 --- a/03-Methods and Functions/01-Methods.ipynb +++ b/03-Methods and Functions/01-Methods.ipynb @@ -21,7 +21,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#Method is a function in an object\n", + "#Ways to know methods:\n", + "#1- help function .. Tab in jupyter\n", + "#2- shift +tab in jupyter\n", + "#3- python standard library" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -170,7 +183,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/03-Function Practice Exercises.ipynb b/03-Methods and Functions/03-Function Practice Exercises.ipynb index cb906db..a0cee6b 100644 --- a/03-Methods and Functions/03-Function Practice Exercises.ipynb +++ b/03-Methods and Functions/03-Function Practice Exercises.ipynb @@ -707,7 +707,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/03-Methods and Functions/07-args and kwargs.ipynb b/03-Methods and Functions/07-args and kwargs.ipynb index 47fa02a..3372204 100644 --- a/03-Methods and Functions/07-args and kwargs.ipynb +++ b/03-Methods and Functions/07-args and kwargs.ipynb @@ -77,23 +77,33 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(40, 60, 20)\n" + ] + }, { "data": { "text/plain": [ "6.0" ] }, - "execution_count": 3, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "#pass as many parameters or arguments as I want\n", "def myfunc(*args):\n", + " print (args) #tuple\n", " return sum(args)*.05\n", + " \n", "\n", "myfunc(40,60,20)" ] @@ -109,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -118,18 +128,49 @@ "6.0" ] }, - "execution_count": 4, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "def myfunc(*spam):\n", - " return sum(spam)*.05\n", + "# We can use any keywards by using * before it\n", + "def myfunc(*mana):\n", + " return sum(mana)*.05\n", "\n", "myfunc(40,60,20)" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "def p_item(*zizo):\n", + " for i in zizo:\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mana\n", + "zizo\n", + "migo\n" + ] + } + ], + "source": [ + "p_item('mana','zizo','migo')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -179,6 +220,39 @@ "myfunc()" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "#** as dictionary \n", + "def vfruit (**kwargs):\n", + " print (kwargs)\n", + " if 'fruit' in kwargs:\n", + " print('my fruit of choice is {}'.format(kwargs['fruit']))\n", + " else:\n", + " print('I did not find any fruit here')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'ffruit': 'mango', 'vegitable': 'lettuce'}\n", + "I did not find any fruit here\n" + ] + } + ], + "source": [ + "vfruit(fruit='mango',vegitable='lettuce')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -246,6 +320,45 @@ "\n", "That's it! Now you should understand how `*args` and `**kwargs` provide the flexibilty to work with arbitrary numbers of arguments!" ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "def myfunc(*args,**kwargs):\n", + " print (args) #tuple\n", + " print(kwargs) #dictionary\n", + " print ('I would like {} {}'.format(args[0],kwargs['food']))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(10, 20, 30)\n", + "{'fruit': 'orange', 'food': 'eggs', 'animals': 'dog'}\n", + "I would like 10 eggs\n" + ] + } + ], + "source": [ + "#we have to be in the same order args firstS>> then kwargs\n", + "myfunc(10,20,30,fruit='orange',food='eggs',animals='dog')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -264,7 +377,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/15-Advanced OOP/01-Advanced Object Oriented Programming.ipynb b/15-Advanced OOP/01-Advanced Object Oriented Programming.ipynb index bb5d231..8db0bcc 100644 --- a/15-Advanced OOP/01-Advanced Object Oriented Programming.ipynb +++ b/15-Advanced OOP/01-Advanced Object Oriented Programming.ipynb @@ -470,7 +470,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.7.3" } }, "nbformat": 4,