You can declare a Global list on the file/module level like my_global_list = list() in Python. If you want to append to it inside a function you can use the global keyword.
Example global list in Python
Simple example code.
aList = []
def bar():
sublist = 1
aList.append(sublist)
bar()
print(aList)
Output:
![Define Global list in Python](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2021/10/Define-Global-list-in-Python.jpg?resize=302%2C152&ssl=1)
Another example
Declare a global list and use it in function.
global a
a = [1, 2, 3]
def update_a():
del a[1:2]
print(a)
update_a()
Output: [1, 3]
Do comment if you have any doubts or suggestions on this Python list.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
So simple! Thanks for sharing.