Feb-14-2018, 09:03 AM
(This post was last modified: Feb-14-2018, 09:03 AM by digitalmatic7.)
I've heard from multiple sources I should try to avoid using global variables, since it's probably a sign of broken / badly written code. Here's an example of what I need to do:
list1 = None list2 = None list3 = None def test(): global list1 list1 = [1, 2, 3, 4, 5] def test2(): global list2 list2 = [6, 7, 8, 9, 10] def test3(): global list3 list3 = [11, 12, 13, 14, 15] test() test2() test3() final_list = list1 + list2 + list3 print() print(final_list) ''' in the full script LOTS of actions will be taken inside each function to generate the lists, this code is just for a very basic example of what I plan to do. '''I'm aware of 'return' and 'function parameters', I've been researching them in my free time today, but I can't get them to replace global variables in this situation.