Skip to content

Added a function file with example #12689

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions other/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
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.

Check failure on line 4 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:4:89: E501 Line too long (116 > 88)
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

Check failure on line 16 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:16:89: E501 Line too long (139 > 88)
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

Check failure on line 23 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:23:89: E501 Line too long (130 > 88)

"""


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

Check failure on line 31 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:31:89: E501 Line too long (109 > 88)
For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5

Check failure on line 32 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:32:89: E501 Line too long (110 > 88)
another way to call a function is to specify the values for example print(addition(a=4 ,b= 5))

Check failure on line 33 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:33:89: E501 Line too long (94 > 88)

"""


"""

Another function for example can be to print every item in a list
For example

"""


def each_item_in_list(list):

Check failure on line 46 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (A002)

other/functions.py:46:23: A002 Function argument `list` is shadowing a Python builtin
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

Check failure on line 50 in other/functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/functions.py:50:89: E501 Line too long (127 > 88)
"""


each_item_in_list([1, 2, 3, 4, 5, 6])

"""
Upon calling the function the result will be
1
2
3
4
5
6
"""
Loading