Source code for AutomateTheBoringStuff.Ch03.P04_sameName

"""Same name

This program uses the same variable name throughout.

Attributes:
    eggs (str): String denoting global variable.

Note:
    Not recommended, but possible.

"""

eggs = 'global'


[docs]def spam() -> None: """Spam Prints its local variable called eggs. Returns: None. Prints the local variable. """ eggs = 'spam local' #: String denoting local variable. print(eggs) # prints 'spam local'
[docs]def bacon() -> None: """Bacon Prints its local variable called eggs and also calls :meth:`spam`. Returns: None. Prints local variables. """ eggs = 'bacon local' #: String denoting local variable. print(eggs) # prints 'bacon local' spam() print(eggs) # prints 'bacon local'
[docs]def main(): bacon() print(eggs) # prints 'global'
if __name__ == '__main__': main()