Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (Retired) Dungeon Game Planning Our Dungeon

What's the difference between Functions with and without arguments?

I kind of understand the arguments when I see them, but I'm not sure yet when should I use functions with or without arguments.

1 Answer

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

Well, it depends of the purpouse of the function. If the output of the function is always going to be the same, for example, a function that prints Hello there, the there is no argument needed.

def hello():
    puts 'Hello there!'

def hello(name):
    puts 'Hello there {}'.format(name)

hello()

hello('Plato')
hello('Socrates')
Laurens Sandt
Laurens Sandt
3,513 Points

The output of the function need not be the same. In fact it could be random number generator and the outcome would be the same as in a random number and different as in a different number