python global variables in a function code example Example 1: global variables python global x x=1 Example 2: how to declare global variable in python global n n = 'whatever'