From 6716e4d37e4a9ed71510748de967bf120750a19d Mon Sep 17 00:00:00 2001 From: DhawalChaturvedi <116241596+DhawalChaturvedi@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:04:57 +0530 Subject: [PATCH 1/2] Added a function file with example --- other/functions.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 other/functions.py diff --git a/other/functions.py b/other/functions.py new file mode 100644 index 000000000000..21ecaeb1116b --- /dev/null +++ b/other/functions.py @@ -0,0 +1,59 @@ +""" +A pure Python implementation of Functions + +A Function in python is a reusable piece of code that takes N parameters and can be called as many times as we want. +Functions are important because: + 1) They make our code clean + 2) They make our code small + 3) It improves performance +For example : A function to add two numbers a and b will have two parameters a and b + +""" + +def addition(a ,b): + """ + A function in python is created with a keyword 'def' in all small , followed with the name of the function for example in here addition + and in the brackets we pass on the parameter's value the function will work upon + + """ + return a + b + + """ + The return keyword as the name suggests returns the result of the function in here it returns the value of addition of a and b + + """ + +print(addition(4,5)) + +""" +To call a function you type in the function's name and pass on the values that you want your function to pass +For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5 +another way to call a function is to specify the values for example print(addition(a=4 ,b= 5)) + +""" + + +""" + +Another function for example can be to print every item in a list +For example + +""" + +def each_item_in_list(list): + for item in list: + print(item) + """ + Here the function takes takes the parameter 'list' and this function when called upon will print every item of the list + """ +each_item_in_list([1,2,3,4,5,6]) + +""" +Upon calling the function the result will be +1 +2 +3 +4 +5 +6 +""" From 1e04f4f7a2a3a42fc133834fcc9d25fbd6b8ff49 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Apr 2025 12:46:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/functions.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/other/functions.py b/other/functions.py index 21ecaeb1116b..abbc2801100b 100644 --- a/other/functions.py +++ b/other/functions.py @@ -1,5 +1,5 @@ """ -A pure Python implementation of Functions +A pure Python implementation of Functions A Function in python is a reusable piece of code that takes N parameters and can be called as many times as we want. Functions are important because: @@ -10,10 +10,11 @@ """ -def addition(a ,b): + +def addition(a, b): """ A function in python is created with a keyword 'def' in all small , followed with the name of the function for example in here addition - and in the brackets we pass on the parameter's value the function will work upon + and in the brackets we pass on the parameter's value the function will work upon """ return a + b @@ -23,11 +24,12 @@ def addition(a ,b): """ -print(addition(4,5)) + +print(addition(4, 5)) """ To call a function you type in the function's name and pass on the values that you want your function to pass -For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5 +For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5 another way to call a function is to specify the values for example print(addition(a=4 ,b= 5)) """ @@ -40,13 +42,16 @@ def addition(a ,b): """ + def each_item_in_list(list): for item in list: print(item) """ Here the function takes takes the parameter 'list' and this function when called upon will print every item of the list """ -each_item_in_list([1,2,3,4,5,6]) + + +each_item_in_list([1, 2, 3, 4, 5, 6]) """ Upon calling the function the result will be