## What Keyword arguments explicitly match [[argument|arguments]] in [[function]] calls to [[parameter|parameters]], using the parameters’ [[identifier]]. ## Syntax A keyword argument is provided using a parameter's identifier directly in the subprogram call, e.g., `text = greet(name="John", greeting="Aloha")`. Positional arguments must be provided before keyword arguments in a subprogram call—keyword arguments cannot come before positional ones when the two are mixed. ## Why Keyword arguments do not change whether an argument is required; they only give flexibility in with the order in which arguments are provided. Using keyword arguments makes longer [[function]] calls more readable by explicitly naming the parameters and [[assign|assigning]] their values. As keyword arguments match by identifier rather than position in the subprogram [[signature]], you can supply them in any order. This flexibility is especially helpful when using [[Default parameters|default parameters]], since it lets you override a later default without re-specifying the ones before it. ## Examples ### Manipulating argument order If you use keyword arguments for all the arguments in the subprogram call, the order does not matter at all. ```python def create_username(forename, surname, year): username = f"{forename[0]}{surname}{year[2:]}" return username user = create_username(forename="Jon", surname="Hamm", year="2025") # JHamm25 user2 = create_username(year="2023", forename="Quintin", surname="Bacon") # QBacon23 ``` ### Combining keyword and positional arguments Keyword arguments must be provided after all positional arguments. ```python def create_username(forename, surname, year): username = f"{forename[0]}{surname}{year[2:]}" return username user = create_username("Frances", "Ford", year="2021") # FFord21 ``` ### Improving readability with default parameters Keyword arguments are useful and improve readability when using [[Default parameters|default parameters]]. ```python def create_username(forename, surname, year="2025"): username = f"{forename[0]}{surname}{year[2:]}" return username user = create_username("Frances", "Ford") # FFord25 — default used user2 = create_username("Frances", "Ford", year="2021") # FFord21 — default overridden ``` ### Improving readability in a long subprogram call As the number of arguments grows, positional calls become hard to parse without checking the signature—keyword arguments fix this by naming each value at the call site. In the first call below, it is ambiguous who the patient and doctor are unless you check the subprogram signature; it is also unclear what `True` and `False` mean. The second call resolves this by naming every value explicitly. ```python def book_appointment(patient_name, doctor, date, time, urgent, video_call): ... book_appointment("Asha Patel", "Olaf Okafor", "2026-07-03", "14:30", True, False) book_appointment( patient_name="Asha Patel", doctor="Olaf Okafor", date="2026-07-03", time="14:30", urgent=True, video_call=False, ) ```