

{"id":6833,"date":"2018-01-30T12:51:35","date_gmt":"2018-01-30T07:21:35","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6833"},"modified":"2026-04-14T11:21:51","modified_gmt":"2026-04-14T05:51:51","slug":"python-function-arguments","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/","title":{"rendered":"Python Function Arguments with Types, Syntax and Examples"},"content":{"rendered":"<p>Previously, we have covered Functions in Python. In this Python Function Arguments tutorial, we will learn about what function arguments are used in Python and their types: Python Keyword Arguments, Default Arguments in Python, and Python Arbitrary Arguments.<\/p>\n<p>So, let&#8217;s start Python Function Arguments.<\/p>\n<h3>What is a Python Function?<\/h3>\n<p><em>Python function is a sequence of statements that execute in a certain order; we associate a name with it. This lets us reuse code.<\/em><\/p>\n<p><strong>Benefits of using functions in Python:<\/strong><\/p>\n<ul>\n<li><strong>Modularity:<\/strong> Functions make the complex problems smaller.<\/li>\n<li><strong>Reusability: <\/strong>Functions allow you to use the same code in different programs.<\/li>\n<li><strong>Maintenance:<\/strong> Functions are easy to maintain and can test a specific part of your code.<\/li>\n<\/ul>\n<p>We define a function using the \u2018def\u2019 keyword. Let\u2019s take an example.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sayhello():\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\"\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 This prints Hello\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\"\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"Hello\")<\/pre>\n<p>Then, to call this, we simply use the function\u2019s name with parentheses. Also, notice the docstring.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sayhello()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hello<\/div>\n<p>This one takes no arguments. Now, let\u2019s see one with Python function arguments.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sum(a,b):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return a+b\r\n&gt;&gt;&gt; sum(2,3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">5<\/div>\n<p>To this, if we pass only one argument in the function, the interpreter complains.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sum(3)\r\nTraceback (most recent call last):\r\nFile \"&lt;pyshell#44&gt;\", line 1, in &lt;module&gt;\r\nsum(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">TypeError: sum() missing 1 required positional argument: &#8216;b&#8217;<\/div>\n<p>To deal with such situations, we see different types of arguments in python functions.<\/p>\n<h3>Types of Python Function Arguments<\/h3>\n<p>There are various types of Python arguments in a function. Let&#8217;s learn them one by one:<\/p>\n<h4>1. Default Argument in Python<\/h4>\n<p>Python Program arguments can have default values. We assign a default value to an argument using the assignment operator in Python (=).<\/p>\n<p>When we call a function without a value for an argument, its default value (as mentioned) is used.<\/p>\n<p>Defaults cut down the number of required inputs. If a caller skips a value with a default, Python fills the gap automatically. Keyword arguments boost clarity by showing which data fills which slot, helpful in long or optional parameter lists.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def greeting(name='User'):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(f\"Hello, {name}\")\r\n&gt;&gt;&gt; greeting('Ayushi')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hello, Ayushi<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; greeting()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hello, User<\/div>\n<p>Here, when we call greeting() without an argument, the name takes on its default value- \u2018User\u2019.<\/p>\n<p>Any number of arguments can have a default value. But you must make sure not to have a non-default argument after a default argument.<\/p>\n<p>In other words, if you provide a default argument, all others succeeding it must have default values as well.<\/p>\n<p>The reason is simple. Imagine you have a function with two parameters.<\/p>\n<p>The first argument has a default value, but the second doesn\u2019t. Now, when you call it(if it were allowed), you provide only one argument.<\/p>\n<p>The interpreter takes it to be the first argument. What happens to the second argument, then? It has no clue.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sum(a=1,b):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return a+b<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">SyntaxError: non-default argument follows default argument<\/div>\n<p>This was all about the default arguments in Python<\/p>\n<h4>2. Python Keyword Arguments<\/h4>\n<p>With keyword arguments in Python, we can change the order of passing the arguments without any consequences.<\/p>\n<p>Let\u2019s take a function to divide two numbers and return the quotient.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def divide(a,b):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return a\/b\r\n&gt;&gt;&gt; divide(3,2)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1.5<\/div>\n<p>We can call this function with arguments in any order, as long as we specify which value goes into what.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; divide(a=1,b=2)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0.5<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; divide(b=2,a=1)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0.5<\/div>\n<p>As you can see, both give us the same thing. These are keyword python function arguments.<\/p>\n<p>But if you try to put a positional argument after a keyword argument, it will throw Python exception of SyntaxError.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; divide(b=2,1)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">SyntaxError: positional argument follows keyword argument in python.<\/div>\n<p>Any Doubt yet in Python Function Arguments<\/p>\n<h4>3. Python Arbitrary Arguments<\/h4>\n<p>You may not always know how many arguments you\u2019ll get. In that case, you use an asterisk(*) before an argument name.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sayhello(*names):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for name in names:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(f\"Hello, {name}\")<\/pre>\n<p>And then when you call the function with several arguments, they get wrapped into a Python tuple.<\/p>\n<p>We iterate over them using the for loop in Python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sayhello('Ayushi','Leo','Megha')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hello, Ayushi<br \/>\nHello, Leo<br \/>\nHello, Megha<\/div>\n<h3>Python Interview Questions on Function Arguments<\/h3>\n<p>1. What are function Arguments in Python?<\/p>\n<p>2. How do you create a function argument in Python?<\/p>\n<p>3. How do you check if a function is an argument in Python?<\/p>\n<p>4. What is an argument in Python? Give an example.<\/p>\n<p>5. What are the types of function arguments in Python?<\/p>\n<h3>Conclusion<\/h3>\n<p>Hence, we conclude that Python Function Arguments and their three types of arguments to functions. These are- default, keyword, and arbitrary arguments.<\/p>\n<p>Where default arguments help deal with the absence of values, keyword arguments let us use any order.<\/p>\n<p>Finally, arbitrary arguments in Python save us in situations where we\u2019re not sure how many arguments we\u2019ll get.<\/p>\n<p>Furthermore, if you have a query, feel free to ask in the comment box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously, we have covered Functions in Python. In this Python Function Arguments tutorial, we will learn about what function arguments are used in Python and their types: Python Keyword Arguments, Default Arguments in Python,&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":42121,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[1067,3701,4967,8028,10365,10484,10549,10631,15864],"class_list":["post-6833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-arbitrary-arguments-in-python","tag-default-arguments-in-python","tag-function-arguments-in-python","tag-keyword-arguments-in-python","tag-python-arbitrary-arguments","tag-python-default-arguments","tag-python-function-arguments","tag-python-keyword-arguments","tag-what-is-python-functions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Function Arguments with Types, Syntax and Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about what Python function arguments are and their types: Keyword Arguments, Default Arguments, and Arbitrary Arguments in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-function-arguments\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Function Arguments with Types, Syntax and Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about what Python function arguments are and their types: Keyword Arguments, Default Arguments, and Arbitrary Arguments in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-function-arguments\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-30T07:21:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-14T05:51:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Function Arguments with Types, Syntax and Examples - DataFlair","description":"Learn about what Python function arguments are and their types: Keyword Arguments, Default Arguments, and Arbitrary Arguments in Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/","og_locale":"en_US","og_type":"article","og_title":"Python Function Arguments with Types, Syntax and Examples - DataFlair","og_description":"Learn about what Python function arguments are and their types: Keyword Arguments, Default Arguments, and Arbitrary Arguments in Python.","og_url":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-30T07:21:35+00:00","article_modified_time":"2026-04-14T05:51:51+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Function Arguments with Types, Syntax and Examples","datePublished":"2018-01-30T07:21:35+00:00","dateModified":"2026-04-14T05:51:51+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/"},"wordCount":741,"commentCount":7,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg","keywords":["Arbitrary Arguments in python","Default Arguments in Python","Function Arguments in Python","Keyword Arguments in python","Python Arbitrary Arguments","Python Default Arguments","Python Function Arguments","Python Keyword Arguments","what is python functions"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-function-arguments\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/","url":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/","name":"Python Function Arguments with Types, Syntax and Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg","datePublished":"2018-01-30T07:21:35+00:00","dateModified":"2026-04-14T05:51:51+00:00","description":"Learn about what Python function arguments are and their types: Keyword Arguments, Default Arguments, and Arbitrary Arguments in Python.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-function-arguments\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Function-Arguments-1024x536-1.jpg","width":1200,"height":628,"caption":"Python Function Arguments with Types, Syntax and Examples"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-function-arguments\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Function Arguments with Types, Syntax and Examples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6833"}],"version-history":[{"count":15,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6833\/revisions"}],"predecessor-version":[{"id":147601,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6833\/revisions\/147601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/42121"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}