Website Hosting for Just 20 ForumCoin ~ Advertise on ForumCoin
52 Life Tips Banner
Get paid up to 150 ForumCoin to submit your article.

Python Functions : Some useful applications

Postby ptrikha21 » 21 Apr 2024, 11:31

I have been doing a Technical course and while my immediate job needs doesn't needs the knowledge of this Programming language, I am studying it as part of the curriculum.
This is the "Python" language(not to be confused with the Reptillian variety :) )
In this regard, I have gone through the language basics, Data Types, Variables, basic conditional and other logic and so on.
Yet for modularity, reuse and repeatability, today's languages rely on Functions(and Stored Procedures) or further packages or libraries a lot.
In this respect, Python functions are pretty useful.
Plus the ease of Python's variable declaration, assignment and usage rules means that one can pretty quickly come up with a useful code for many needs.

Let's explore further:

We try our code on Google Colab :

https://colab.research.google.com/drive/1qhgLCsxG8zb5RQ0G9bZnUmyBl3mXRfw7#scrollTo=dsgAEt0hIByn

A)Simple Python Function:


def simple_python_fun() :
print("first and simple function")

#Now let's call the function :

simple_python_fun()

Output : String :

first and simple function


B)Python function to check whether an input number is odd or even.
# Text are the comments.

# Python function to check
# whether input_num1 is even or odd

def evenOddCheck(input_num1):
if (input_num1 % 2 == 0):
print(input_num1 , "is \t Even Number")
else:
print(input_num1 , "is \t Odd Number")

evenOddCheck(10)
evenOddCheck(23)

Output :

10 is Even Number
23 is Odd Number

C)Function to add up numbers and show the sum :
The below function takes up N number of non-keyword arguments :

def sum_of_nums(*input_nums):
print("\n Data Type of arguments :", type(input_nums))
sum = 0

for n in input_nums :
sum = sum + n

return sum


First we pass :
sum_of_nums(1,2,9,12,24,35)

result :

Data Type of arguments : <class 'tuple'>
83

Then :
sum_of_nums(90,100,200)

Data Type of arguments : <class 'tuple'>
390

We can add any random number of digits.
Above, we also see the data types that we pass.

The Functions can be used to accomplish much more - Mathematical functions, Analytics, Averages and more.


The image is of an execution done during running of this program.


For more such thought provoking Articles, insights and discussions, do come and join the wonderful world of Forumcoin. An English language forum, where you can discuss and share idqeas and opinions on a variety of topics.
For sign up, click here :
https://forumcoin.com/index.php?r=5080

-- 21 Apr 2024, 17:03 --

  • 0

Attachments
Simple_Python_Fun_21Apr24.PNG
Python Functions
Simple_Python_Fun_21Apr24.PNG (16.31 KiB) Viewed 178 times
User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby Fergal » 24 Apr 2024, 05:55

Thanks for sharing those with us ptrikha21. Do you use Python yourself in your work, or is it a side hobby?
  • 0

User avatar
Fergal
Site Admin
 
Posts: 14,877
Location: Ireland
ForumCoin: 14,639

Re: Python Functions : Some useful applications

Postby ptrikha21 » 25 Apr 2024, 09:55

Fergal wrote:Thanks for sharing those with us ptrikha21. Do you use Python yourself in your work, or is it a side hobby?


Frankly Python is a key subject in Data Analytics. I am doing it as part of my Data Analytics studies.
A lot lot remains to be done.
I am amazed by how vast Python is and its applications.
  • 1

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby Fergal » 26 Apr 2024, 05:43

Good for you ptrikha21, are you studying Data Analytics by yourself or are you doing a course in the subject?
  • 0

User avatar
Fergal
Site Admin
 
Posts: 14,877
Location: Ireland
ForumCoin: 14,639

Re: Python Functions : Some useful applications

Postby ptrikha21 » 26 Apr 2024, 07:01

Fergal wrote:Good for you ptrikha21, are you studying Data Analytics by yourself or are you doing a course in the subject?


I have joined a fully self paced online course. So far, I have not been up to speed, but now getting more regular.
There are costlier and higher duration courses as well. Yet, with a full time day job, it becomes a challenge to devote sufficient time for such extra courses.
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby Fergal » 27 Apr 2024, 05:17

Good luck and continued success with your course ptrikha21, I hope it goes well for you and that you can find the time to continue working on it.
  • 0

User avatar
Fergal
Site Admin
 
Posts: 14,877
Location: Ireland
ForumCoin: 14,639

Re: Python Functions : Some useful applications

Postby ptrikha21 » 27 Apr 2024, 14:38

Fergal wrote:Good luck and continued success with your course ptrikha21, I hope it goes well for you and that you can find the time to continue working on it.


Thank you for your wishes. I hope to further my learning and skill enhancement in this field and overall into the vast vast field of Data Analytics.
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby mrki444 » 28 Apr 2024, 08:35

@Fergal please edit his post and add this code in code tag.
Python is sensitive on spaces and tabs. When somebody try copy his code from above it will send many errors.
Also code tag is much more readable.
  • 0

mrki444
 
Posts: 29,585
Location: Croatia
Referrals: 1
ForumCoin: 1,202

Re: Python Functions : Some useful applications

Postby ptrikha21 » 28 Apr 2024, 09:44

mrki444 wrote:@Fergal please edit his post and add this code in code tag.
Python is sensitive on spaces and tabs. When somebody try copy his code from above it will send many errors.
Also code tag is much more readable.


Yes, indentation and space is an important factor. I cannot edit myself. So yes, Fergal can do it.
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby mrki444 » 29 Apr 2024, 19:54

@ptrikha21

do you use online compiler or local installed python enviroment?
  • 0

mrki444
 
Posts: 29,585
Location: Croatia
Referrals: 1
ForumCoin: 1,202

Re: Python Functions : Some useful applications

Postby ptrikha21 » 07 May 2024, 14:22

mrki444 wrote:@ptrikha21

do you use online compiler or local installed python enviroment?


I have tried IDE that comes with usual Python download.
Yet for this Article and normal practice now a days, I am using Google Colab:

https://colab.research.google.com/
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby mrki444 » 09 May 2024, 20:03

It is better than programiz.com online compiler in free version. In free version it can't call modul for visualization.
  • 0

mrki444
 
Posts: 29,585
Location: Croatia
Referrals: 1
ForumCoin: 1,202

Re: Python Functions : Some useful applications

Postby ptrikha21 » 12 May 2024, 10:25

mrki444 wrote:It is better than programiz.com online compiler in free version. In free version it can't call modul for visualization.

I have not tried Programiz.com so cannot say. For basic operations, Google Colab is reasonable enough.
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113

Re: Python Functions : Some useful applications

Postby mrki444 » 16 May 2024, 16:36

Did you work any time with API? Data are often send from backend in trough API and then present as charts.
  • 0

mrki444
 
Posts: 29,585
Location: Croatia
Referrals: 1
ForumCoin: 1,202

Re: Python Functions : Some useful applications

Postby ptrikha21 » 18 May 2024, 16:19

mrki444 wrote:Did you work any time with API? Data are often send from backend in trough API and then present as charts.


I have not reached exploring the API stage.
I have been more of a Database Guy along with being active as Configuration & Release Manager.
Now I am diversifying and keen on gaining Analytics skills and Python is a critical component in that.
  • 0

User avatar
ptrikha21
 
Posts: 7,387
Location: India
Referrals: 5
ForumCoin: 1,113



Your Ad Here.

Return to Articles & Tutorials



Who is online

Users browsing this forum: Claude [Bot], Yandex [Bot] and 1 guest

Reputation System ©'