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