Python dictionary in Hindi

What is Python Function

Function एक reusable blocks of code है जिसका use किसी specific task  को perform करने के लिए किया जाता है। जब भी हमे अपने program मे ऐसे block of code की जरूरत पड़ती है जिसका use पूरे program मे कई बार होने वाला होता है तो उस code का function बना लेते है जिससे हमे उस code को बार बार लिखने की जरूरत नहीं होती हम बस उस function को call करेंगे हमारा काम हो जाएगा ।

How to Create Function

Def: Def keyword का use  करके हम function define करते है,

Function name: किसी function को identify करने के लिए उसका एक unique name होता है जिसे हम function name कहते है । 

Function Body: इसमे function का वो code होता है जो किसी specific task perform करता है।

SYNTEX

def function_name( ):
       # Function body
       # return

Scope in Function

किसी variable को program में कहा तक access किया जा सकता है उसे ही scope उस variable का scope कहते है। Python में mainly 2 types के scope होते है-

Local Scope and Local Variable

अगर हम function के अंदर कोई variable बनाते है तो उसका use सिर्फ उसी function मे ही हो सकता है इसे ही local scope कहा जाता है, और ऐसे variables को local variable कहते कहते है। 

Global Scope and Global Variable

ऐसे variables जो function body या किसी भी block के बाहर बनाते है उन्हे global variables कहा जाता है, इन variables को पूरे program मे कही भी use किया जा सकता है, और उस variable के scope को global scope कहेंगे।  

Global Keyword

अगर हम चाहते है कि function के अंदर जो variable है उसका use कही भी कर सके तो उसके लिए global keyword का use करना होगा

Function Return

जब हम कोई function create करते है तो वो by default “none” return करता है, but अगर हम function से किसी value को return करना चाहते है तो return keyword का use करके एक या एक से अधिक values को return करा सकते है। function जो भी value return करेगा वो function calling के जगह पर आ जाएगा।

Note : जब function के अंदर का code चलता हो तो return मिलते है function का execution complete हो जाता है अगर हमने function body में return line के नीचे कोई code लिखा है तो वो execute नहीं होगा, इसलिए return को हमेशा last में लिखा जाता है but किसी specific condition पर हम return को बीच में भी use करते है।

Aliasing Function

Aliasing का मतलब होता है किसी function को दो अलग-अलग नाम से use करना ऐसा हम तब करते है जब किसी function नाम hard होता है तो हम एक simple नाम में उसे बदल देते है। aliasing करने के लिए हमे बस एक variable को create करना है और उसमे function name को assign कर देना अब हम उस variable को as a function use कर सके है।

Pass Statement

अगर हम function को define करके उसके function body मे कोई code न लिखे तो यह error देगा । error से बचने के लिए हम pass का use करते है.

SYNTEX

def function_name():
    pass

उम्मीद करते है कि आपको Python Function अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Electronics
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
computer networks

Table of Contents All Chapters 1. OSI Model      1.1. Physical Layer      1.2. Data Link Layer  ...

computer networks

Table of Contents All Chapters 1. Topology 2. Types of Topology      2.1. Point to Point Topology    ...

computer networks

Table of Contents All Chapters 1. Data Communication 2. Types of Data Communication      2.1. Simplex      2.2....

digital electronics number system

Table of Contents All Chapters 1. Logic Gate 2. AND Gate      2.1. AND Gate Truth Table 3. OR...

Edit Template

Sign up to track your learning

Login to continue your learning tracking

To reset your password, please enter your email address or username below.

Scroll to Top