Lesson 23 of 34

Default, Keyword Arguments

8 min 30 XP

Parameter-ന് ഒരു default value നൽകൂ. Caller അത് നൽകിയില്ലെങ്കിൽ default ഉപയോഗിക്കും.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Keyword arguments: values പേര് ഉപയോഗിച്ച് നൽകൂ, അപ്പോൾ ക്രമം പ്രശ്നമല്ല. കോഡ് വായിക്കാനും എളുപ്പമാകും.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Default ഉള്ള parameters ഇല്ലാത്തവയ്ക്ക് ശേഷം വരണം: def f(a, b=2) ശരി, def f(a=1, b) error ആണ്.

Challenge

+30 XP

ശതമാന discount-ന് ശേഷമുള്ള അന്തിമ വില return ചെയ്യുന്ന price(amount, discount=10) എഴുതൂ: amount - amount * discount // 100 ഉദാഹരണം: price(1000) → 900, price(1000, 20) → 800

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.