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 trialWilfredo Casas
6,174 PointsWhat'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
18,132 PointsWell, 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
3,513 PointsLaurens Sandt
3,513 PointsThe 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