Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 1 of 10 · Functions and Lambda Expressions
Interview question

What is a function in Python and what is function scope? Python में function क्या है और function scope क्या होता है?

Answer

Function is reusable code block. Scope determines variable accessibility. Python has 4 scopes: Local, Enclosing, Global, Built-in (LEGB rule).

def greet(name):
    message = f'Hello {name}'  # Local
    return message

global_var = 'global'

def show():
    print(global_var)  # Access global

show()

Function reusable code block है। Scope variable को कहाँ access कर सकते हैं यह decide करता है। 4 scopes: Local, Enclosing, Global, Built-in

Was this answer clear?