Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
6af20ed
Var len
Aniruddh-0701 Oct 16, 2020
304d88d
Create Cheat_sheet-checkpoint.pdf
Aniruddh-0701 Oct 16, 2020
9281670
Update
Aniruddh-0701 Oct 16, 2020
bb71ec2
update
Aniruddh-0701 Oct 16, 2020
298f22f
Update Introduction_to_Python_Programming.ipynb
Aniruddh-0701 Oct 16, 2020
309b507
Update
Aniruddh-0701 Oct 16, 2020
62b7e33
Created
Aniruddh-0701 Oct 16, 2020
f17aadf
Update
Aniruddh-0701 Oct 17, 2020
0ae9ae8
Update DS_Lists.ipynb
Aniruddh-0701 Oct 17, 2020
6e37eb8
Dictionaries
Aniruddh-0701 Oct 17, 2020
12ddb21
Create practice code
Aniruddh-0701 Oct 17, 2020
37b4853
update
Aniruddh-0701 Oct 17, 2020
c5c1681
update
Aniruddh-0701 Oct 17, 2020
c2ee3ea
Update
Aniruddh-0701 Oct 21, 2020
35be559
Created sets
Aniruddh-0701 Oct 21, 2020
b9d7aed
set methods
Aniruddh-0701 Oct 23, 2020
8e49032
update
Aniruddh-0701 Oct 23, 2020
b551271
Introduction to modules and packages
Aniruddh-0701 Oct 23, 2020
9713fc0
update
Aniruddh-0701 Oct 23, 2020
6c69649
Added prime_gen.py for modules
Aniruddh-0701 Oct 26, 2020
5bab1b5
Added code
Aniruddh-0701 Oct 26, 2020
1384228
update
Aniruddh-0701 Oct 26, 2020
b181bae
Added code
Aniruddh-0701 Oct 26, 2020
1db702a
update
Aniruddh-0701 Oct 26, 2020
af19e4c
Deleted
Aniruddh-0701 Oct 26, 2020
afebc5e
Update
Aniruddh-0701 Oct 26, 2020
669a62e
Update
Aniruddh-0701 Oct 26, 2020
c1736f3
Update
Aniruddh-0701 Oct 26, 2020
4eebc26
update
Aniruddh-0701 Oct 26, 2020
61a5d4e
update
Aniruddh-0701 Oct 26, 2020
ba842ef
Update
Aniruddh-0701 Oct 27, 2020
0ff173c
update
Aniruddh-0701 Oct 28, 2020
b3f8a7a
Packages
Aniruddh-0701 Oct 28, 2020
1fb448a
OOPS
Aniruddh-0701 Oct 30, 2020
b6c0972
Update
Aniruddh-0701 Oct 30, 2020
68dd187
Update
Aniruddh-0701 Nov 5, 2020
e21324e
Added links
Aniruddh-0701 Dec 2, 2020
bacaf21
Classes
Aniruddh-0701 Dec 3, 2020
30001e3
Update vector.py
Aniruddh-0701 Dec 4, 2020
3433e63
Update vector.py
Aniruddh-0701 Dec 4, 2020
5056a12
Updates
Aniruddh-0701 Jan 21, 2021
f834aa9
Update README.md
Aniruddh-0701 Jan 25, 2021
e2fc5c5
Update README.md
Aniruddh-0701 Jan 25, 2021
bc7f561
Added a book
Aniruddh-0701 Mar 9, 2021
25ca58a
Update README.md
Aniruddh-0701 Mar 9, 2021
fdff826
Update Installing_and_Using_Python.md
Aniruddh-0701 Mar 14, 2021
9769583
Updated
Aniruddh-0701 Apr 6, 2021
6cfeba3
Added gitignore
Aniruddh-0701 May 16, 2021
45f10f4
added docs for github pages
Aniruddh-0701 May 16, 2021
ea95f35
Set theme jekyll-theme-cayman
Aniruddh-0701 May 16, 2021
ee31dd3
Set theme jekyll-theme-cayman
Aniruddh-0701 May 16, 2021
34e38eb
Set theme jekyll-theme-slate
Aniruddh-0701 May 16, 2021
e6dd0f0
Set theme jekyll-theme-cayman
Aniruddh-0701 May 16, 2021
a583a37
Set theme jekyll-theme-cayman
Aniruddh-0701 May 16, 2021
6ba9964
Removed mds
Aniruddh-0701 May 16, 2021
c43cfa7
Merge branch 'master' of https://github.com/Aniruddh-0701/Python_Prog…
Aniruddh-0701 May 16, 2021
d78e781
Updates as html
Aniruddh-0701 May 16, 2021
4855728
Update README.md
Aniruddh-0701 May 16, 2021
4b0cae9
Update Installing_and_Using_Python.md
Aniruddh-0701 May 16, 2021
c77039b
Updated Links
Aniruddh-0701 May 20, 2021
68c2b07
Updates in formatting
Aniruddh-0701 May 23, 2021
aa787af
Added new books
Aniruddh-0701 Jun 2, 2021
2d3cc65
Updates
Aniruddh-0701 Jun 2, 2021
6b1438e
Updates for OOPS
Aniruddh-0701 Jul 22, 2021
7fbaa9a
Updates
Aniruddh-0701 Jul 22, 2021
e217f08
Updated README
Aniruddh-0701 Jul 22, 2021
3f48bca
Syntax highlight update
Aniruddh-0701 Jul 24, 2021
7ee28a5
Added content on fields and methods
Aniruddh-0701 Jul 24, 2021
fd3aab4
Updated the notes for Exception Handling
Aniruddh-0701 Jul 24, 2021
20b2523
Syntax highlight and code updates
Aniruddh-0701 Jul 24, 2021
eb4f68e
Updates
Aniruddh-0701 Jul 25, 2021
8197f88
Update .gitignore
Aniruddh-0701 Jul 25, 2021
5608336
Updated questions
Aniruddh-0701 Jul 25, 2021
58ea5d4
minor fixes
Aniruddh-0701 Jul 25, 2021
d2dcb73
Updates on functions
Aniruddh-0701 Jul 25, 2021
ad8c3d5
Updates and fixes
Aniruddh-0701 Jul 25, 2021
bc4ab8d
Added details on Fields and methods
Aniruddh-0701 Jul 25, 2021
0a66edd
Updated file format
Aniruddh-0701 Jul 26, 2021
04d37d0
Minor fixes
Aniruddh-0701 Jul 26, 2021
f9ca925
Format changes
Aniruddh-0701 Jul 26, 2021
4867b33
Format Updates
Aniruddh-0701 Jul 26, 2021
b9e812b
Format Updates
Aniruddh-0701 Jul 26, 2021
2a8860e
Added effects for markdown
Aniruddh-0701 Jul 30, 2021
a1c41cf
Update .gitignore
Aniruddh-0701 Aug 2, 2021
5807737
Name change
Aniruddh-0701 Aug 2, 2021
67dbc15
Updated the format
Aniruddh-0701 Aug 2, 2021
d5db940
Changed color and added a css element
Aniruddh-0701 Aug 2, 2021
74af10b
Latex fixes
Aniruddh-0701 Aug 2, 2021
1ac8fcd
Latex FIxes
Aniruddh-0701 Aug 2, 2021
c7aaca8
Update Practice_code1.md
Aniruddh-0701 Aug 17, 2021
761cb8e
Updated Cheat Sheet reference
Aniruddh-0701 Aug 17, 2021
8fb2682
Added a useful link
Vaishnaviamirayada Jul 26, 2022
f799e18
Merge pull request #1 from Vaishnaviamirayada/patch-1
Aniruddh-0701 Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates on functions
  • Loading branch information
Aniruddh-0701 committed Jul 25, 2021
commit d2dcb73466515a98c543b4794a205e6003bc6513
109 changes: 97 additions & 12 deletions .ipynb_checkpoints/Functions-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,29 @@
"# 13"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Naming a function\n",
"\n",
"Like variables, python functions should also be in `lower_snake_case`\n",
"\n",
"One of the more universal, yet simple rules is: Function names should be verbs if the function changes the state of the program, and nouns if they're used to return a certain value.\n",
"\n",
"1. *Self-explanatory names*: a function `get_name()` will tell the developer what it returns as well as set_address(), is_male(), etc.\n",
"2. *Short*: a function name must be as short as possible so that it's simple to type as well as easy to remember. A function `get_number_of_pages_in_the_book()` is not good, something like `get_book_page_count()` is better.\n",
"3. Use of prefixes: use prefixes in the functions such as `get_name()`, `set_name()`, etc.\n",
"\n",
"The most important thing to note is to follow a constant naming convention throughout the function"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lambda function (Inline or Anonymous function):\n",
"One liner of a function\n",
"One liner of a function. It is created for use at one point or one statememt and is not intended to be named and stored.\n",
"\n",
"Syntax: \n",
"```python\n",
Expand All @@ -93,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -107,21 +124,33 @@
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
"From is_even(x): True\n",
"From lambda: True\n"
]
}
],
"source": [
"# Example 1\n",
"# def c(x):\n",
"# return x % 2 == 0 #One line function to check if even\n",
"\n",
"def is_even(x):\n",
" return x % 2 == 0 # One line function to check if even\n",
"\n",
"a = int(input())\n",
"c = lambda x: x % 2 == 0 # Equivalent lambda function\n",
"print(c(a))\n",
"print(\"From is_even(x):\", is_even(a))\n",
"print(\"From lambda:\", (lambda x: x % 2 == 0)(a)) # Equivalent lambda function\n",
"\n",
"# Input: 10"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `lambda` function is generally created for use with iterables where the function is applied to several values but at only once (that part of the code).\n",
"\n",
"The usual places include maps, filter and keys for sorting for any iterable. Visit [Lists](DS_Lists.ipynb) or [Tuples](DS_Tuples.ipynb) to know more on them"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -177,6 +206,7 @@
"source": [
"Breaking down of problem:\n",
"\n",
"```python\n",
"n = 6 \n",
"n <= 1 False \n",
"6 * factorial(5) \n",
Expand All @@ -203,14 +233,69 @@
"\n",
"Building up:\n",
"\n",
"1 <br>\n",
"1\n",
"2 * 1 \n",
"3 * 2 * 1 \n",
"4 * 3 * 2 * 1 \n",
"5 * 4 * 3 * 2 * 1 \n",
"6 * 5 * 4 * 3 * 2 * 1 \n",
"\n",
"720"
"720\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can find the steps in recursion below \n",
"The '|' line indicates the same level of recursive call"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6\n",
"|\t5\n",
"|\t|\t4\n",
"|\t|\t|\t3\n",
"|\t|\t|\t|\t2\n",
"|\t|\t|\t|\t|\t1\n",
"|\t|\t|\t|\t2\n",
"|\t|\t|\t6\n",
"|\t|\t24\n",
"|\t120\n",
"720\n"
]
},
{
"data": {
"text/plain": [
"720"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The indent paramter defines the offset of output. This program is to understand recursion only.\n",
"def fact(n, indent=''):\n",
" print(indent, n, sep='')\n",
" if 0 <= n <= 1: return 1\n",
" else:\n",
" fac = n * fact(n-1, indent + \"|\\t\")\n",
" print(indent, fac, sep='')\n",
" return fac\n",
"\n",
"fact(6)"
]
},
{
Expand Down Expand Up @@ -459,7 +544,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -488,7 +573,7 @@
"source": [
"#Example\n",
"# Example \n",
"def add(a, *b): # Function Definition - * incicates variable length arguments\n",
"def add(a, *b): # Function Definition - * indicates variable length arguments\n",
" print(b)\n",
" return a + sum(b) # returns the sum; sum is a built in function that returns sum of elements in an iterable\n",
"x = int(input())\n",
Expand Down Expand Up @@ -1230,7 +1315,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
109 changes: 97 additions & 12 deletions Functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,29 @@
"# 13"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Naming a function\n",
"\n",
"Like variables, python functions should also be in `lower_snake_case`\n",
"\n",
"One of the more universal, yet simple rules is: Function names should be verbs if the function changes the state of the program, and nouns if they're used to return a certain value.\n",
"\n",
"1. *Self-explanatory names*: a function `get_name()` will tell the developer what it returns as well as set_address(), is_male(), etc.\n",
"2. *Short*: a function name must be as short as possible so that it's simple to type as well as easy to remember. A function `get_number_of_pages_in_the_book()` is not good, something like `get_book_page_count()` is better.\n",
"3. Use of prefixes: use prefixes in the functions such as `get_name()`, `set_name()`, etc.\n",
"\n",
"The most important thing to note is to follow a constant naming convention throughout the function"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lambda function (Inline or Anonymous function):\n",
"One liner of a function\n",
"One liner of a function. It is created for use at one point or one statememt and is not intended to be named and stored.\n",
"\n",
"Syntax: \n",
"```python\n",
Expand All @@ -93,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -107,21 +124,33 @@
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
"From is_even(x): True\n",
"From lambda: True\n"
]
}
],
"source": [
"# Example 1\n",
"# def c(x):\n",
"# return x % 2 == 0 #One line function to check if even\n",
"\n",
"def is_even(x):\n",
" return x % 2 == 0 # One line function to check if even\n",
"\n",
"a = int(input())\n",
"c = lambda x: x % 2 == 0 # Equivalent lambda function\n",
"print(c(a))\n",
"print(\"From is_even(x):\", is_even(a))\n",
"print(\"From lambda:\", (lambda x: x % 2 == 0)(a)) # Equivalent lambda function\n",
"\n",
"# Input: 10"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `lambda` function is generally created for use with iterables where the function is applied to several values but at only once (that part of the code).\n",
"\n",
"The usual places include maps, filter and keys for sorting for any iterable. Visit [Lists](DS_Lists.ipynb) or [Tuples](DS_Tuples.ipynb) to know more on them"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -177,6 +206,7 @@
"source": [
"Breaking down of problem:\n",
"\n",
"```python\n",
"n = 6 \n",
"n <= 1 False \n",
"6 * factorial(5) \n",
Expand All @@ -203,14 +233,69 @@
"\n",
"Building up:\n",
"\n",
"1 <br>\n",
"1\n",
"2 * 1 \n",
"3 * 2 * 1 \n",
"4 * 3 * 2 * 1 \n",
"5 * 4 * 3 * 2 * 1 \n",
"6 * 5 * 4 * 3 * 2 * 1 \n",
"\n",
"720"
"720\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can find the steps in recursion below \n",
"The '|' line indicates the same level of recursive call"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6\n",
"|\t5\n",
"|\t|\t4\n",
"|\t|\t|\t3\n",
"|\t|\t|\t|\t2\n",
"|\t|\t|\t|\t|\t1\n",
"|\t|\t|\t|\t2\n",
"|\t|\t|\t6\n",
"|\t|\t24\n",
"|\t120\n",
"720\n"
]
},
{
"data": {
"text/plain": [
"720"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The indent paramter defines the offset of output. This program is to understand recursion only.\n",
"def fact(n, indent=''):\n",
" print(indent, n, sep='')\n",
" if 0 <= n <= 1: return 1\n",
" else:\n",
" fac = n * fact(n-1, indent + \"|\\t\")\n",
" print(indent, fac, sep='')\n",
" return fac\n",
"\n",
"fact(6)"
]
},
{
Expand Down Expand Up @@ -459,7 +544,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -488,7 +573,7 @@
"source": [
"#Example\n",
"# Example \n",
"def add(a, *b): # Function Definition - * incicates variable length arguments\n",
"def add(a, *b): # Function Definition - * indicates variable length arguments\n",
" print(b)\n",
" return a + sum(b) # returns the sum; sum is a built in function that returns sum of elements in an iterable\n",
"x = int(input())\n",
Expand Down Expand Up @@ -1230,7 +1315,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
Loading