r/learnpython • • Oct 25 '26

Why parameters finally made sense to me today

Hey everyone, just wanted to share a quick lightbulb moment I had with Python today about why functions actually need parameters.

At first, I didn't get why we couldn't just write functions without them. But it clicked today: parameters are basically just empty placeholder slots so your function can handle changing data.

Without a Parameter (Fixed)

It can only ever do one exact thing:

Python

def greet():
    print("Hello, Alice!")

greet()  # Always prints "Hello, Alice!"

With a Parameter (Dynamic)

Adding name gives you a slot inside the function. When you call it, you just pass whatever data you want into that slot:

Python

def greet(name):
    print(f"Hello, {name}!")

greet("Alice")  # Prints: Hello, Alice!
greet("Bob")    # Prints: Hello, Bob!

My main takeaway: If the code inside your function needs to work with different information every time, you need a parameter to pass that data in from the outside!

0 Upvotes

15 comments sorted by

4

u/neuralbeans Oct 25 '26

It would help to compare against the functions that Python provides you. Imagine if print didn't have arguments.

1

u/Boybay_Garid Oct 25 '26

true, people pass things into print() on day one without even realizing theyre already using arguments

1

u/Mikeybarnes Oct 25 '26

Print can run without arguments, but that doesn't mean it has no parameters. 

1

u/TheRNGuy Oct 26 '26

Because they're all optional (using default values if not provided)

1

u/TheRNGuy Oct 26 '26 edited Oct 26 '26

Without arguments, it's less versatile or reusable function.

Some functions still don't need them (some functions firing some side effects have 0 arguments)

Though in these both cases, you don't need to create functions just to put print in it.

1

u/LayotFctor Oct 25 '26 edited Oct 25 '26

I like thinking of functions as conveyor belt machines, looking similar to a printer. It has a start button at the side where you can call it, as well as input and output slots.

By adding a parameter, you added an input to the machine where you can give it names. If you didn't add a parameter, you hardcode "Hello, Alice!" into the internals of the machine instead. A machine with an input can be reused to print lots of things. A machine with a hardcoded string can print that and only that.

This view of functions as machines can go very far. An entire program is just a factory full of machines connected together. Data enters at the loading bay, gets fed into one machine after another, altered and shaped along the way until you finally get the desired result.

-10

u/Anxious_Signature452 Oct 25 '26

You can also do:

NAME = 'Alice'
def greet():
    print(f"Hello, {NAME}")

10

u/TabAtkins Oct 25 '26

You can, but using globals is almost never a good idea. Definitely not good to bring up as an option for someone who's just learned the very basics of functions.

0

u/igotshadowbaned Oct 25 '26

I've found that creating everything within a class and using class variables works better than globals with python anyway

5

u/Kermit_the_hog Oct 25 '26

Yeah, next topic for OP to look at: variable scope.

2

u/VipeholmsCola Oct 25 '26

you could, but you shouldnt

0

u/frnzprf Oct 25 '26

That wouldn't work if multiple calls of the same functions are nested in each other.

That's where you either need a stack (last-in-first-out list) or parameters which are actually implemented in the background as a stack.

That's why you get a stack-overflow with infinite recursion.

I tried to find an example where your system doesn't work, but here it works at least:

def fibonacci():
    global argument
    if argument < 3:
        return 1
    else:
        original_arg = argument
        
        argument = original_arg - 1
        part1 = fibonacci()
        
        argument = original_arg - 2
        part2 = fibonacci()
        
        return part1 + part2

argument = 8
print(fibonacci()) # 21 is correct

0

u/CranberryDistinct941 Oct 25 '26

Chaotic evil code block