To create a global list in Python, you can declare the list outside of any function or class, making it accessible to all parts of your code. Here's an example:
main.py172 chars9 lines
In the example above, global_list
is defined outside of any function, making it a global variable. The add_item_to_list
function updates the global list by appending a new item. Be sure to use the global
keyword inside any function that needs to access or modify the global list.
gistlibby LogSnag