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 Basics Functions and Looping Returning Values

I don't understand how "word" works in this script

def display_blanks( word):
    blanks = "-" * len(word)
    print(blanks)

print("Puzzle 1:")
display_blanks("treehouse")
print("Puzzle 2:")
display_blanks( "python")

2 Answers

Hi there can Unsal! The word in this case is called a parameter. It is what is passed into a function when it is called, which is called an argument.

In this case

def display_blanks(word):
    blanks = "-" * len(word)
    print(blanks)

display_blanks("treehouse")

The python interpreter is going through the function with what is passed in as an argument when display_blanks() is called. display_blanks("treehouse") would make blanks = "-" * len("treehouse") which would output "---------"

The parameter of a function is a placeholder for whatever is entered when the function is called.

I hope this helps!

Michael Jacoby
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Jacoby
Front End Web Development Techdegree Student 4,657 Points

Another way to say this to the noobs - like me - is that word is a placeholder for the word that will be used (to determine how many hyphens there will be). In this case, word = both treehouse (9) and python (6), so that placeholder word is used to generate output. parameter word, arguments treehouse, python

I get that this is being used to teach us something, but to me it's not practical. I don't know anyone in the real world - coding for a company - that would use words to determine how many hyphens there will be. Atop that, the output doesn't look uniform. Seems to me it'd be better to just use the print function and use the same amount of hyphens.

... still learning

... long way to go