Important Notice:

Calling Function with Default Arguments

Calling Function with Default Arguments

17 views 1 min read

Calling Function with Default Arguments :-

Default arguments वाले function को call करते समय हम argument दे भी सकते हैं और छोड़ भी सकते हैं। यदि argument नहीं दिया जाता, तो default value उपयोग होती है।

 in English

When calling a function with default arguments, we may provide an argument or omit it. If the argument is omitted, the default value is used.

Example 1: Calling Without an Argument

def show_course(course="O Level"):
    print("Course:", course)

show_course()

Output: Course: O Level

Explanation: Argument नहीं दिया गया, इसलिए default value "O Level" का उपयोग हुआ।

Example 2: Calling With an Argument

def show_course(course="O Level"):
    print("Course:", course)

show_course("Python")

Output:

Course: Python

Explanation: "Python" argument देने के कारण default value "O Level" की जगह "Python" का उपयोग हुआ।

Example 3: Calling With and Without Arguments

def calculate_square(number=5):
    print("Square:", number * number)

calculate_square()
calculate_square(4)
calculate_square(10)

Output:

Square: 25
Square: 16
Square: 100

Explanation:

  • calculate_square() में default value 5 उपयोग हुई।

  • calculate_square(4) में 4 उपयोग हुआ।

  • calculate_square(10) में 10 उपयोग हुआ।

 

Related Notes