Hi all,
For this function:
def two_word_shout(word1,word2):
return word1+'!'*3+' '+word2+'!'*3
two_word_shout('congratulations','you') outputs 'congratulations!!! you!!!' whereas enclosing in print() generates the same output without the quotes. Why the difference, exactly?
PyDev console: starting.
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
def two_word_shout(word1,word2):
return word1 + '!' * 3 + ' ' + word2 + '!' * 3
two_word_shout('congratulations','you')
'congratulations!!! you!!!'
print(two_word_shout('congratulations','you'))
congratulations!!! you!!!
This happens only in interactive mode. The first time you do not say what you want with the result, so Python shows it to you
and also shows quotation marks to let you know it is a string type.
The second time you print the value and the print function just prints the result without letting you know the type of what you are printing.
You also need to realise that printing and returning are not at all the same. The former writes the value to the standard output stream, so the print
function returns None
. In the latter case, the value returned is made available to the caller and can hence be used in further computations.