Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
When invoking functions, passing data into them reliably is essential. To master function calls, you must first understand the distinction between two related terms:
def calculate_emi(principal, tenure):).calculate_emi(500000, 5)).Python provides two distinct ways to bind arguments to parameters: Positional Arguments (matched by sequential order) and Keyword Arguments (matched by parameter name).
+-------------------------------------------------------------------------------+
| ARGUMENT BINDING REAL-WORLD ANALOGIES |
+-------------------------------------------------------------------------------+
1. THE FACTORY CONVEYOR BELT (Positional Arguments):
- An assembly worker receives three slots: [Engine, Wheels, Chassis].
- The parts arrive on a physical conveyor belt in strict sequence:
Part 1 ALWAYS goes to Engine, Part 2 to Wheels, Part 3 to Chassis.
- If the delivery order gets swapped, the machine assembles a backwards car!
- Position and order dictate meaning.
2. SPEED POST LABELED PARCELS (Keyword Arguments):
- A courier delivery truck carries three labeled boxes:
`recipient="Vikram"`, `pincode=110001`, `fragile=True`
- The postal delivery driver can pull boxes out in ANY arbitrary order:
the box marked `pincode=110001` will ALWAYS go to the pincode slot,
because the explicit label guarantees unambiguous routing.
+-------------------------------------------------------------------------------+Positional arguments are the default in most programming languages. Arguments are mapped one-to-one with parameters based strictly on their physical position from left to right:
Output:
Notice how swapping the arguments in the second call corrupted the output without raising a syntax error!
Keyword arguments pass values in the format parameter_name = value. Because each value is explicitly labeled, the order in which they appear in the function call does not matter:
Output:
Python allows mixing positional and keyword arguments in the same function call. However, you must adhere strictly to The Cardinal Rule:
You cannot assign a value to the same parameter more than once:
*Python allows function authors to enforce that certain critical arguments must always be passed as keywords. This is done by placing an asterisk * in the parameter list:
Keyword-only parameters prevent accidental bugs when functions accept boolean flags.
| Best Practice (DO) | Dangerous Anti-Pattern (DON'T) |
|---|---|
DO use positional arguments for natural primary inputs (e.g. math.sin(x)). | DON'T place positional arguments after keyword arguments (SyntaxError). |
| DO use keyword arguments for configuration options, optional flags, and boolean toggles. | DON'T supply multiple values for the same parameter both positionally and via keyword (TypeError). |
DO use the * delimiter to enforce keyword-only arguments for safety-critical settings. | DON'T rely on positional arguments when a function accepts 5+ parameters; use keyword arguments for readability. |
name=value and can be supplied in any order.SyntaxError.* in a parameter list marks all subsequent parameters as keyword-only.return StatementIf a function computes a value but doesn't return it, Python returns None by default:
global KeywordReading a global variable is permitted, but assigning to it creates a local variable unless explicitly declared:
A. Output: Good Morning, Karan! B. SyntaxError: positional argument follows keyword argument C. TypeError: greet() takes 2 arguments but got 1 D. Output: None, Karan!
A. I have a Sheru named Dog. B. I have a Dog named Sheru. C. TypeError: unexpected keyword order D. I have a animal_type named pet_name.
A. SyntaxError: invalid syntax B. TypeError: got multiple values for argument 'user_id' C. ValueError: duplicate key D. NameError: user_id redefined
debug_mode can ONLY be passed as a keyword argument?A. def log(msg, @debug_mode): B. def log(msg, *, debug_mode): C. def log(msg, kw_only(debug_mode)): D. def log(msg, kwargs: debug_mode):
A. Parameters are used in loops; arguments are used in conditionals B. Parameters are variables defined in the function signature; arguments are the real values passed in during invocation C. Parameters must be strings; arguments must be numbers D. There is no difference; they are exact technical synonyms
Build an automated order dispatch and delivery fee calculator for an Indian food delivery platform (Swiggy / Zomato).
Create a modular dispatch function: dispatch_food_order(customer_name, restaurant_name, distance_km, *, is_prime_member=False, applied_coupon="NONE", tip_inr=0.0)
customer_name, restaurant_name, and distance_km are positional arguments.is_prime_member, applied_coupon, and tip_inr must be keyword-only arguments enforced by *.is_prime_member == True: 100% discount on delivery fee (Free Delivery)."SWIGGYIT": Rs 50 off the final bill."ZOMATO50": 20% off the final bill (up to a max of Rs 100).In the next lesson, we will continue your Python learning journey with *Arguments: Default, args, kwargs (14: Functions).
👉 *[Continue to Next Lesson: Arguments: Default, args, kwargs →](/tutorials/python-for-beginners/arguments-default-args-kwargs)
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Defining & Calling Functions | Arguments: Default, *args, **kwargs |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.