Q. What are the rules for local and global variables in Python?


Answer =

In Python, variables that are only referenced inside a function are called implicitly global. If a variable is assigned a new value anywhere within the function body, it is assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local and you need to explicitly declare it as 'global'.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post