+ 1

Def function

Hi there, why don't we use 'print' before this last 'my_func()' to run it correctly? Could you please explain the difference here between printing things and just raw function? def my_func(): print("spam") print("spam") print("spam") my_func()

13th Apr 2018, 6:31 AM
chionae
chionae - avatar
2 ответов
+ 4
As far as I understand your question, you want to know why didn't we use print(my_func()) ? It is because that function doesn't return anything. It already has the print statement which prints out as soon as you call it. Had it been a return statement, you need to use the print() to display what the function might have returned. def my_func(): return "spam" print(my_func()) Check this for more, https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2287/
13th Apr 2018, 6:57 AM
Dev
Dev - avatar
+ 1
there is no difference... just print() always defined in default libraries and avialable everywhere..
13th Apr 2018, 6:46 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar