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 default नसलेल्यांच्या नंतर यायला हवेत: def f(a, b=2) चालते, def f(a=1, b) error आहे.

Challenge

+30 XP

टक्केवारी सवलतीनंतरची अंतिम किंमत 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.