Lesson 23 of 34

Default & Keyword ArgumentsDefault & Keyword Arguments

8 min 30 XP

ஒரு parameter-க்கு இயல்பு மதிப்பு (default) கொடுக்கலாம். அழைக்கும் போது அதைக் கொடுக்காவிட்டால் default பயன்படுத்தப்படும்.

Give a parameter a default value. If the caller leaves it out, the default is used.

Example: edit me and press Run

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

Keyword arguments: பெயரைச் சொல்லி மதிப்பைக் கொடுத்தால் வரிசை முக்கியமில்லை. இதனால் code படிக்கவும் எளிதாகும்.

Keyword arguments: pass values by name and the order no longer matters. It also makes code easier to read.

Example: edit me and press Run

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

default உள்ள parameters, default இல்லாதவற்றுக்குப் பின்னால் தான் வர வேண்டும்: def f(a, b=2) சரி, def f(a=1, b) தவறு.

Parameters with defaults must come after those without: def f(a, b=2) is fine, def f(a=1, b) is an error.

Challenge

+30 XP

price(amount, discount=10) என்ற function எழுதுங்கள். தள்ளுபடி சதவீதத்தைக் கழித்து இறுதி விலையை return செய்ய வேண்டும்: amount - amount * discount // 100 உதாரணம்: price(1000) → 900, price(1000, 20) → 800

Write price(amount, discount=10) that returns the final price after the percentage discount: amount - amount * discount // 100 Example: price(1000) → 900, price(1000, 20) → 800

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