Lesson 23 of 34

Default మరియు Keyword Arguments

8 min 30 XP

ఒక parameter కి default విలువ ఇవ్వండి. పిలిచేవారు దాన్ని ఇవ్వకపోతే 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: విలువలను పేరుతో పంపితే క్రమం ముఖ్యం కాదు. కోడ్ చదవడం కూడా సులభమవుతుంది.

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) error.

Challenge

+30 XP

శాతం డిస్కౌంట్ తర్వాత తుది ధరను తిరిగి ఇచ్చే 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.