Welcome to Admin Junkies, Guest — join our community!

Register or log in to explore all our content and services for free on Admin Junkies.

Python Functions in Python

Jason

Royal member
Bronze Member
Joined
Nov 3, 2022
Messages
1,446
Website
drummerlesson.com
Credits
31
Functions in Python are factories. Of course, this is true with any coding language and developers need these factories because it keeps them from writing code over and over. Anyway, functions are not something native to programming. It was in math before programming came on the scene. For instance, y = x^2 (y equals x squared) is the function of a parabola. When something is put in, something comes out, cause it's a factory.

Diving In

Let's dive in a study some code. It's all sort of self-explanatory if you look at it long enough. However, feel free to ask questions about it. I mean, sometimes things can get rough.

Code:
def multiply_function(a, b):

    print(a * b)
  
# Let's call the function.

multiply_function(5, 5)

""" This should print out 5 * 5 which equals 25.  It does this because we put two
arguments in the function corresponding to a and b and the function multiplies them. """
 
The code looks good, runs nicely.

Unfortunately I do need to nitpick this:

Functions in Python are factories. Of course, this is true with any coding language and developers need these factories because it keeps them from writing code over and over.
They are not factories; factories have a very specific technical meaning, primarily in object-orientated code. There are plenty of languages whose functions do not support being factories.

What we can say is that a function is a description of how to do some work and that you write it once so you can reuse it. The idea being that you write it once, and reuse it everywhere else so you don't keep writing new code (that you have to test, and maintain). It also means that if you change how something works, you can change it once and everything will follow it.

The underlying theory's right, but functions are such a backbone of programming that to not get functions as a concept screws up all other understanding - and it's where the detail can be important.
 
The code looks good, runs nicely.

Unfortunately I do need to nitpick this:


They are not factories; factories have a very specific technical meaning, primarily in object-orientated code. There are plenty of languages whose functions do not support being factories.

What we can say is that a function is a description of how to do some work and that you write it once so you can reuse it. The idea being that you write it once, and reuse it everywhere else so you don't keep writing new code (that you have to test, and maintain). It also means that if you change how something works, you can change it once and everything will follow it.

The underlying theory's right, but functions are such a backbone of programming that to not get functions as a concept screws up all other understanding - and it's where the detail can be important.
Actually, all the code I've written on the site runs good now. I edited all of it. Go try it out sometime if you want.
 
Last edited:

Log in or register to unlock full forum benefits!

Log in or register to unlock full forum benefits!

Register

Register on Admin Junkies completely free.

Register now
Log in

If you have an account, please log in

Log in
Activity
So far there's no one here

Users who are viewing this thread

Would You Rather #9

  • Start a forum in a popular but highly competitive niche

    Votes: 5 21.7%
  • Initiate a forum within a limited-known niche with zero competition

    Votes: 18 78.3%
Win this space by entering the Website of The Month Contest

Theme editor

Theme customizations

Graphic Backgrounds

Granite Backgrounds