{"id":22352,"date":"2020-11-16T13:09:21","date_gmt":"2020-11-16T21:09:21","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=22352"},"modified":"2023-12-01T04:04:04","modified_gmt":"2023-12-01T12:04:04","slug":"python-optional-arguments","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/","title":{"rendered":"Python Optional Arguments: A How-To Guide"},"content":{"rendered":"\n<p><em>A Python optional argument is a type of argument with a default value. You can assign an optional argument using the assignment operator in a function definition or using the Python **kwargs statement.<\/em><\/p>\n\n\n\n<p>There are two types of arguments a Python function can accept: positional and optional. Optional arguments are values that do not need to be specified for a function to be called.<\/p>\n\n\n\n<p>In this guide, we talk about what optional arguments are and how they work.<\/p>\n\n\n\n<p>We\u2019ll walk you through an example of optional arguments so you can learn how to use them in your programs. We\u2019ll also discuss how to use the **kwargs method to accept variable numbers of arguments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Python Argument?<\/h2>\n\n\n\n<p>An argument is a value that is <a href=\"https:\/\/careerkarma.com\/blog\/python-functions\/\">accepted by a Python function<\/a>. This value becomes its own <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">Python variable<\/a> that can be used within a function. Consider the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def show_the_day(day):\n\t   print(&quot;Hello there. Today is {}.&quot;.format(day))\n\nshow_the_day(&quot;Thursday&quot;)<\/pre><\/div>\n\n\n\n<p>In this code, \u201cday\u201d is an argument. Whatever value you specify in parentheses when you call the show_the_day function will become \u201cday\u201d. In this case, \u201cThursday\u201d is \u201cday\u201d.<\/p>\n\n\n\n<p>The number of values we specify in a function call must be equal to the number of arguments that a function accepts. This is unless we use optional arguments. In which case, we can specify fewer arguments than a function accepts because some arguments are optional.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Optional Arguments<\/h2>\n\n\n\n<p>A Python optional argument is an argument with a default value. You can specify a default value for an argument using the assignment operator. There is no need to specify a value for an optional argument when you call a function. This is because the default value will be used if one is not specified.<\/p>\n\n\n\n<p>Arguments can have default values. This makes an argument optional. If an argument has a default value, then it will use that default value if no other value is specified.<\/p>\n\n\n\n<p>Default arguments are assigned using the assignment operator:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def print_student(student, grade=&quot;Fifth&quot;):\n\tprint(&quot;{} is in {} grade.&quot;.format(student, grade))<\/pre><\/div>\n\n\n\n<p>This user-defined function accepts two arguments: student and grade. Grade is an optional function argument which means we do not need to specify a value for it when we call the print_student() function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Optional Arguments Python Example<\/h3>\n\n\n\n<p>We\u2019re going to write a program that counts how many of a particular coffee was sold at a coffee shop on a Thursday morning. To start, define a list of coffees that were sold that morning:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>coffees_sold = [&quot;Espresso&quot;, &quot;Espresso&quot;, &quot;Latte&quot;, &quot;Cappuccino&quot;, &quot;Mocha&quot;, &quot;Espresso&quot;, &quot;Latte&quot;]<\/pre><\/div>\n\n\n\n<p>Next, write a function that counts how many of a particular coffee was sold:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def count_coffees(coffees, to_find=&quot;Espresso&quot;):\n\t   number_sold = coffees.count(to_find)\n\t   print(&quot;{} {} coffees were sold.&quot;.format(number_sold, to_find))<\/pre><\/div>\n\n\n\n<p>This function accepts two arguments: coffees and to_find.\n\n<\/p>\n\n\n\n<p>The first argument is the list of coffees. Our second argument is the name of the coffee whose total sales we want to calculate. The <a href=\"https:\/\/careerkarma.com\/blog\/python-count\/\">Python count() method<\/a> counts how many instances of the coffee for which we are looking exists in the \u201ccoffees\u201d list.\n\n<\/p>\n\n\n\n<p>The second argument is optional. If we don\u2019t specify a value for the \u201cto_find\u201d argument, that argument will become equal to \u201cEspresso\u201d. Next, let&#8217;s call the function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>count_coffees(coffees_sold, &quot;Latte&quot;)<\/pre><\/div>\n\n\n\n<p>This function call will make the value of \u201cto_find\u201d equal to \u201cLatte\u201d in our code. Let\u2019s run the program and see what happens:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>2 Latte coffees were sold.<\/pre><\/div>\n\n\n\n<p>The code tells us that two lattes were sold. Now, call our function without a second value:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>count_coffees(coffees_sold)<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>3 Espresso coffees were sold.<\/pre><\/div>\n\n\n\n<p>We specified no value for \u201cto_find\u201d so, by default, its value became \u201cEspresso\u201d. We can see that if we specify no value for an argument, its default value is used. Otherwise, the value we specify is used for the argument.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python Function Optional Arguments Error<\/h3>\n\n\n\n<p>Optional parameters must appear after required arguments when you define a function. Required arguments are those that do not have a default value assigned.<\/p>\n\n\n\n<p>Required arguments are often called &#8220;required positional arguments&#8221; because they must be assigned at a particular position in a function call. If you specify an optional argument before a required argument, Python returns an error that looks like this:\n\n<\/p>\n\n\n\n<p><a href=\"https:\/\/careerkarma.com\/blog\/python-positional-argument-follows-keyword-argument\/\">positional argument follows keyword argument<\/a>\n\n<\/p>\n\n\n\n<p>This is because if optional arguments came before required arguments then it will eliminate the purpose of optional arguments. How would Python know what values to assign to what arguments if the optional ones came first?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Optional Arguments Python: **kwargs<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/careerkarma.com\/blog\/python-args-kwargs\/\">**kwargs<\/a> keyword passes arguments to a function that are assigned to a particular keyword. **kwags represents an aribitrary number of keywords, whether that is zero, one, or more keywords. So, you can use **kwargs to use an optional argument with a function.<\/p>\n\n\n\n<p>Let\u2019s write a program that prints out information about the grades a student has earned on their tests to the console. To start, define a dictionary with some information about a student:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>amy = {\n\t  &quot;Name&quot;: &quot;Amy&quot;,\n\t  &quot;Final Assessment&quot;: 74,\n\t  &quot;Second Test&quot;: 72,\n\t  &quot;First Test&quot;: 68\n}<\/pre><\/div>\n\n\n\n<p>Our dictionary contains four keys and values. We\u2019re going to write a function that prints out values from this dictionary to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def show_grades(student, **grades):\n\t   print(&quot;Student record for {}: &quot;.format(student))\n\n\t   for key, value in grades.items():\n\t\t        print(&quot;{} earned a grade of {} in their {}.&quot;.format(student, value, key))<\/pre><\/div>\n\n\n\n<p>This function prints out a message stating \u201cStudent record for X\u201d, where X is equal to the name of a student.<\/p>\n\n\n\n<p>Next, our program prints out all the items in the \u201cgrades\u201d variable to the console. \u201cgrades\u201d uses the \u201c**\u201d syntax which means it contains a dictionary of keys and values over which we can iterate in our program.<\/p>\n\n\n\n<p>Let\u2019s call our function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>show_grades(amy[&quot;Name&quot;], SecondTest=amy[&quot;Second Test&quot;])<\/pre><\/div>\n\n\n\n<p>We have specified two arguments: the name of the student and the score they earned on their second test. The second argument needs to have a keyword because **kwargs represents keyword arguments.&nbsp;<\/p>\n\n\n\n<p>Let&#8217;s run our code and see if it works:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Student record for Amy:\nAmy earned a grade of 72 in their SecondTest.<\/pre><\/div>\n\n\n\n<p>Our program informs us about the grade Amy, a student, earned in their second test. Try to pass another test score through our function as an argument:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>show_grades(amy[&quot;Name&quot;], FirstTest=amy[&quot;First Test&quot;], SecondTest=amy[&quot;Second Test&quot;])<\/pre><\/div>\n\n\n\n<p>Our function now accepts three arguments. The last two arguments are keyword arguments. Let\u2019s run our program:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Student record for Amy:\nAmy earned a grade of 68 in their FirstTest.\nAmy earned a grade of 72 in their SecondTest.<\/pre><\/div>\n\n\n\n<p>Our program shows us the grades that Amy earned in both her first and second test. This is because the **kwargs keyword accepts a variable number of arguments.<\/p>\n\n\n\n<p>Our program also works if we do not specify any keyword arguments:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>show_grades(amy[&quot;Name&quot;])<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Student record for Amy:<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>You can define Python function optional arguments by specifying the name of an argument followed by a default value when you declare a function. You can also use the **kwargs method to accept a variable number of arguments in a function.<\/p>\n\n\n\n<p>To learn more about coding in Python, read our <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-python\/\">How to Learn Python guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"A Python optional argument is a type of argument with a default value. You can assign an optional argument using the assignment operator in a function definition or using the Python **kwargs statement. There are two types of arguments a Python function can accept: positional and optional. Optional arguments are values that do not need&hellip;","protected":false},"author":240,"featured_media":18430,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-22352","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Optional Arguments: A How-To Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Optional Arguments: A How-To Guide\" \/>\n<meta property=\"og:description\" content=\"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-16T21:09:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:04:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"662\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Optional Arguments: A How-To Guide\",\"datePublished\":\"2020-11-16T21:09:21+00:00\",\"dateModified\":\"2023-12-01T12:04:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/\"},\"wordCount\":1050,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/\",\"name\":\"Python Optional Arguments: A How-To Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg\",\"datePublished\":\"2020-11-16T21:09:21+00:00\",\"dateModified\":\"2023-12-01T12:04:04+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg\",\"width\":1020,\"height\":662},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-optional-arguments\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Optional Arguments: A How-To Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Optional Arguments: A How-To Guide | Career Karma","description":"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.","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:\/\/careerkarma.com\/blog\/python-optional-arguments\/","og_locale":"en_US","og_type":"article","og_title":"Python Optional Arguments: A How-To Guide","og_description":"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.","og_url":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-11-16T21:09:21+00:00","article_modified_time":"2023-12-01T12:04:04+00:00","og_image":[{"width":1020,"height":662,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Optional Arguments: A How-To Guide","datePublished":"2020-11-16T21:09:21+00:00","dateModified":"2023-12-01T12:04:04+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/"},"wordCount":1050,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/","url":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/","name":"Python Optional Arguments: A How-To Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg","datePublished":"2020-11-16T21:09:21+00:00","dateModified":"2023-12-01T12:04:04+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Optional arguments are arguments that do not need a value. On Career Karma, learn how to accept optional arguments in a Python function.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-optional-arguments\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/paul-esch-laurent-6MeMUw5KDss-unsplash.jpg","width":1020,"height":662},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-optional-arguments\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Optional Arguments: A How-To Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/22352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=22352"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/22352\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18430"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=22352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=22352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=22352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}