---
title: "Using global variables in a function other than the one that created them"  
description: "Using global variables in a function other than the one that created them"  
author: "Samuel Fernandes"  
published: 2015-05-14  
updated: 2015-05-15  
canonical: https://www.mindstick.com/forum/23227/using-global-variables-in-a-function-other-than-the-one-that-created-them  
category: "python"  
tags: ["python"]  
reading_time: 1 minute  

---

# Using global variables in a function other than the one that created them

If I create a [global variable](https://answers.mindstick.com/qa/104739/define-global-variable) in one [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server), how can I use that variable in another function?\
Do I need to [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) the global variable in a [local variable](https://www.mindstick.com/forum/158997/can-a-local-variable-s-memory-be-accessed-outside-its-scope) of the function which needs its [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china)?

## Replies

### Reply by Anonymous User

You can use a [global](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) in other functions by declaring it as global in each function that assigns to it:\

```
globvar = 0def set_globvar_to_one():    global globvar    # Needed to modify global copy of globvar    globvar = 1def print_globvar():    print globvar     # No need for global declaration to read value of globvarset_globvar_to_one()print_globvar()       # Prints 1
```

I imagine the reason for it is that, since global variables are so dangerous, Python wants to make sure that you really know that's what you're playing with by explicitly requiring the global keyword.


---

Original Source: https://www.mindstick.com/forum/23227/using-global-variables-in-a-function-other-than-the-one-that-created-them

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
