Example of how to create a global variable in python:
Table of contents
Using global
To declare for example a as a global variable:
global a
Illustration with a function
Using global variables in a function:
>>> global a,b
>>> a = 0.5
>>> b = 2
>>> def function( x ):
... return a * x + b
...
>>> function(1)
2.5
>>> b = 4
>>> function(1)
4.5
Related posts
Links | Site |
---|---|
How to apply a function to a list in python ? | moonbooks.org |
How to pass optional arguments in a python function ? | moonbooks.org |