May-10-2019, 07:38 AM
(This post was last modified: May-10-2019, 07:41 AM by road2knowledge.)
Hi folks,
I'm new to programming and python, and I don't understand why if you call a custom function from the same file it's defined in, you get duplicate output.
e.g. a file "question.py" containing the following:
And if I were to manually input "double(2)" after running the module, the output seems perfectly normal (just one 4).
Why is that? And is there a way to avoid the duplicate apart from calling the function from a separate py file?
I know this must have been asked before, but I couldn't find it via forum search or Google (the queries all return questions related to list modification).
Thanks in advance for clearing up my confusion!
I'm new to programming and python, and I don't understand why if you call a custom function from the same file it's defined in, you get duplicate output.
e.g. a file "question.py" containing the following:
1 2 3 4 5 |
def double(number): return number * 2 from question import double print (double( 1 )) |
Why is that? And is there a way to avoid the duplicate apart from calling the function from a separate py file?
I know this must have been asked before, but I couldn't find it via forum search or Google (the queries all return questions related to list modification).
Thanks in advance for clearing up my confusion!