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.