Feb-08-2020, 02:33 PM
(This post was last modified: Feb-08-2020, 02:39 PM by new_to_python.)
(Feb-08-2020, 01:23 PM)metulburr Wrote: i have been using python now for about 10 years. 10 years ago i learned about globals, but i seriously forgot most of it because i never use them. C/C++ is not Python, it is not good practice in Python to use globals. That said, if your just trying to understand the concept, thats fine. I just figured i would reverberate the fact globals can be coded a different way.
Thanks. Yes, I am just trying to understand the concept.
(Feb-08-2020, 02:54 AM)Larz60+ Wrote: globals are almost never necessary.
If you feel you need them, rethink your coding
def bind_a_variable(): alist = [] return alist a = bind_a_variable()of course in reality, you would code this simply as:
a = []
By "of course in reality, you would code this simply as:
a = [][/quote]"
Do you mean either of these two blocks of code will work?
In C, we need to define the function first at the beginning of the program before calling it (e.g. in main).
Alternatively, if the programmer define the function at the end of the program (after the function is called by main for example), the programmer needs to write down the prototype of the function at the beginning of the program. How about python?