Multiple default arguments वाले Functions
अब आपने एक ऐसा फंक्शन परिभाषित कर लिया है जो default argument इस्तेमाल करता है — यहीं मत रुकिए! अब आप एक से ज़्यादा default arguments वाले फंक्शन को परिभाषित करेंगे और फिर उसे अलग-अलग तरीकों से कॉल करेंगे.
फंक्शन परिभाषित करने के बाद, आप इसे फंक्शन के सभी default arguments के लिए मान देकर कॉल करेंगे। इसके अलावा, आप फंक्शन को ऐसे भी कॉल करेंगे जहाँ किसी एक default argument के लिए मान नहीं देंगे — देखें कि इससे आपके फंक्शन का आउटपुट कैसे बदलता है!
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Functions का परिचय
अभ्यास निर्देश
- फंक्शन हेडर को फंक्शन नाम
shout_echoसे पूरा करें। यह क्रम से एक argumentword1, एक default argumentecho(default मान1) और एक default argumentintense(default मानFalse) स्वीकार करता है. ifस्टेटमेंट के बॉडी में, string ऑब्जेक्टecho_wordपर.upper()मेथड लगाकर उसे upper case में बदलें।shout_echo()को string"Hey",echoके लिए मान5औरintenseके लिए मानTrueके साथ कॉल करें। परिणाम कोwith_big_echoमें असाइन करें।shout_echo()को string"Hey"औरintenseके लिए मानTrueके साथ कॉल करें। परिणाम कोbig_no_echoमें असाइन करें।
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Define shout_echo
def ____(____, ____, ____):
"""Concatenate echo copies of word1 and three
exclamation marks at the end of the string."""
# Concatenate echo copies of word1 using *: echo_word
echo_word = word1 * echo
# Make echo_word uppercase if intense is True
if intense is True:
# Make uppercase and concatenate '!!!': echo_word_new
echo_word_new = ____ + '!!!'
else:
# Concatenate '!!!' to echo_word: echo_word_new
echo_word_new = echo_word + '!!!'
# Return echo_word_new
return echo_word_new
# Call shout_echo() with "Hey", echo=5 and intense=True: with_big_echo
with_big_echo = ____
# Call shout_echo() with "Hey" and intense=True: big_no_echo
big_no_echo = ____
# Print values
print(with_big_echo)
print(big_no_echo)