how we increment a global variable value som few functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulhere
    New Member
    • Apr 2007
    • 3

    #1

    how we increment a global variable value som few functions

    send some example
    how we increment a global variable value som few functions
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by rahulhere
    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.
    Code:
    aGlobal = 12
    def IncGlobal():
        global aGlobal
        aGlobal += 1
    
    IncGlobal()
    
    print aGlobal

    Comment

    • iamgame
      New Member
      • Sep 2008
      • 4

      #3
      Originally posted by bartonc
      [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:

      Code:
      global aGlobal
      aGlobal = 12
      def IncGlobal():
          global aGlobal
          aGlobal += 1
      
      IncGlobal()
      
      print aGlobal

      Comment

      Working...