{
  "id": 17746556,
  "title": "python : positional argument, default argument",
  "url": "https://urgent.news/2026/11/02/python-positional-argument-default-argument",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-02T05:02:59.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/sajin_joe/python-positional-argument-default-argument-2p6e"
  },
  "original_language": "en",
  "account": "In Python, functions accept values through positional arguments and default arguments. Positional arguments are passed based on the order of parameters in the function definition. For example:\n\ndef student(name, age):\nprint(name)\nprint(age)\n\nstudent(\"Sajin\", 20)\n\nThe output will be:\nSajin\n20\n\nIf the order of arguments is changed, it will cause an error as the values are matched based on their position.\n\ndef student(age, name):\nprint(name)\nprint(age)\n\nstudent(20, \"Sajin\")\n\nOutput:\n20\nSajin\n\nIn this case, age is assigned 20 and name is assigned Sajin, which is different from the previous example.\n\nDefault arguments in Python are defined within the function definition and have a value assigned to them. If no value is passed during the function call, Python uses the default value. For instance:\n\ndef login(username=\"admin\", password=\"1234\"):\nprint(username, password)\n\nlogin()\n\nThe output will be:\nadmin 1234\n\nThis is because no arguments are provided, so Python uses the default values \"admin\" and \"1234\". However, if custom values are passed:\n\nlogin(\"Sajin\", \"5678\")\n\nOutput:\nSajin 5678\n\nHere, \"Sajin\" replaces the default username, and \"5678\" replaces the default password. The default password remains \"1234\" if only the username is provided:\n\nlogin(\"Sajin\")\n\nOutput:\nSajin 1234\n\nPositional arguments and default arguments can be combined in a single function definition. Positional arguments must come before default arguments. An incorrect function definition would be placing a default argument after a positional argument, which is not allowed:\n\ndef login(username=\"admin\", age=20):\nprint(username, age)\n\nThis function definition is incorrect. The correct order is:\n\ndef login(username, age=20):\nprint(username, age)\n\nThis rule ensures that positional arguments are clearly defined before default arguments in the function definition.",
  "summary": "In Python, positional arguments and default arguments are used when passing values to a function. 1. Positional arguments A positional argument is passed according to the position (order) of the parameter. def student ( name , age ): print ( name ) print ( age ) student ( \" Sajin \" , 20 ) Output : Sajin 20 Step-by-step Parameter Argument name \"Sajin\" age 20 Python matches values based on their…",
  "key_points": [
    "Positional arguments are passed based on their order in function definition.",
    "Default arguments have assigned values in function definition.",
    "Default values are used if no arguments are provided during function call."
  ],
  "editors_take": "Strict adherence to argument ordering ensures that Python can reliably map passed values to their intended parameters while allowing default values to provide fallback logic for missing inputs.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}