A python basic question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

A python basic question

the result of this code prints >HI! but i didnt called the function, can anyone interpret what is happening here? def some_func(): print("Hi!") var = some_func() print(var)

30th Jun 2018, 1:05 PM
sanju sk
sanju sk - avatar
3 Answers
+ 1
You called it via the variable "var".
30th Jun 2018, 1:17 PM
Paul Grasser
Paul Grasser - avatar
+ 1
i thought var only contains the return value,
30th Jun 2018, 1:24 PM
sanju sk
sanju sk - avatar
+ 1
If there was a return value, var would be assigned to it. But the entire loop would have been checked, and it would have printed hi either way.
30th Jun 2018, 1:42 PM
Andre Daniel
Andre Daniel - avatar