Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 Online
OpenStudy (anonymous):

def printTwice(bruce): print bruce, bruce >>> printTwice('Spam') Spam Spam >>> printTwice(5) 5 5 >>> printTwice(3.14159) 3.14159 3.14159 Why in the def there is a comma in the statements ? but when you execute the function with a value the comma doesnt show

OpenStudy (anonymous):

why wouldnt it be just def printTwice(bruce): print bruce bruce

OpenStudy (anonymous):

what does the comma indicate /do

OpenStudy (anonymous):

You need the comma because you're passing two arguments to the print statement. When the function is called and the print statement is ran, the comma keeps the output on the same line because the default of print is to add a newline.

OpenStudy (anonymous):

so in this case the word bruce becomes reserved? its printing the arguement once and then calling it once after the comma ? if u wanted to a string bruce ud have to quote it ?

OpenStudy (anonymous):

Let me caveat this by saying I'm also a beginner. But I think that when you define the function, bruce is a parameter. When you call the function it expects an argument that it stores in bruce. For instance if you call printTwice() without an argument, you'll get a Traceback. If you call printTwice(bruce) and bruce hasn't been assigned a value, you'll also get an error. So to finally answer your question, yes if you want printTwice() to print bruce either quote it or assign the string bruce to a variable and pass that as the argument to printTwice()

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!