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