By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,404 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,404 IT Pros & Developers. It's quick & easy.

how we increment a global variable value som few functions

P: 3
send some example
how we increment a global variable value som few functions
May 2 '07 #1
Share this Question
Share on Google+
2 Replies


bartonc
Expert 5K+
P: 6,596
send some example
how we increment a global variable value som few functions
[Next time, a "please" would be nice.] Posting examples of what you are doing is also helpful to those trying to provide help.
Expand|Select|Wrap|Line Numbers
  1. aGlobal = 12
  2. def IncGlobal():
  3.     global aGlobal
  4.     aGlobal += 1
  5.  
  6. IncGlobal()
  7.  
  8. print aGlobal
May 2 '07 #2

iamgame
P: 4
[Next time, a "please" would be nice.] Posting examples of what you are doing is also helpful to those trying to provide help.
How about using the global variable outside the function too? The following code should work:

Expand|Select|Wrap|Line Numbers
  1. global aGlobal
  2. aGlobal = 12
  3. def IncGlobal():
  4.     global aGlobal
  5.     aGlobal += 1
  6.  
  7. IncGlobal()
  8.  
  9. print aGlobal
Sep 23 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.