<jupyter_start><jupyter_text>**Scope of a variable**<jupyter_code># Local variables are declared inside function and can not be accessed outside of the function
def local_var_example():
    '''Local variables are declared inside function and can not be accessed outside of the function'''
    name = 'Anil'
    print(global_var_example.__doc__)
    print(name, 'is accessed inside the function', local_var_example.__name__)

local_var_example()

# Outside of the function local_var_example and it will throw NameError
#print(name, 'is accessed outside the function', local_var_example.__name__)
# Global variables are declared outside function and can be accessed both inside and outside of the function
last_name = 'Adhikari'
def global_var_example():
    '''Global variables are declared outside function and can be accessed both inside and outside of the function'''
    print(global_var_example.__doc__)
    print(last_name, 'is accessed inside the function', global_var_example.__name__)

global_var_example()
# Outside of the function local_var_example and it will throw NameError
print(last_name, 'is accessed outside the function', global_var_example.__name__)<jupyter_output>Global variables are declared outside function and can be accessed both inside and outside of the function
Adhikari is accessed inside the function global_var_example
Adhikari is accessed outside the function global_var_example
{'fraction_non_alphanumeric': 0.05598866052445074, 'fraction_numerical': 0.0, 'mean_word_length': 6.06, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '501183', 'license': 'MIT', 'n_tokens_mistral': 357, 'n_tokens_neox': 356, 'n_words': 158, 'path': '03 Deep Dive- Functions and OOPs/03_scope_of_variable.ipynb', 'repo_name': 'aadhikar/python-3-basics-and-beyond', 'size': '1411'}