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 trialrudy19
Python Web Development Techdegree Student 507 PointsCreating a function
•When creating: def yell(text) •What is the purpose/significance of entering "text" in the parameters? •What if I entered "number" instead? •And will the function still work if I type: def yell() •Or will it all come back faulty because the function is being used for editing text that is going to be printed, thus why we enter "text"?
•Also, why can't I enter space when a question?
•I have to press enter key twice to not have my sentences glued together like the ones above
1 Answer
John Lack-Wilson
8,181 PointsThe text parameter between the parenthesis allows you to use the variable text within the function. If you do not specify a parameter then you cannot use one within the function. Here's an example of two functions to clear it up (hopefully):
def hello(name):
print("Hello, " + name)
def hello():
print("Hello, ")
You'll notice in the second hello()
function I cannot use name, as it was not passed to the function for me to use. Whereas, I am able to customise a greeting in the first hello(name)
function.
As per your second question. You could use number as the name of the parameter if you wanted to. It is a variable i.e. it can hold whatever value you want it to. Best practice would be to call it something that makes sense, like my name parameter in the above functions.