{"id":245,"date":"2023-04-07T04:06:30","date_gmt":"2023-04-07T04:06:30","guid":{"rendered":"https:\/\/joseph-t-gordon.tech\/?p=245"},"modified":"2023-06-26T14:24:23","modified_gmt":"2023-06-26T14:24:23","slug":"post-43-parameterized-functions-in-python","status":"publish","type":"post","link":"https:\/\/joseph-t-gordon.tech\/index.php\/2023\/04\/07\/post-43-parameterized-functions-in-python\/","title":{"rendered":"Post #43 (Python Programming) &#8211; Parameterized functions in Python"},"content":{"rendered":"\n<p>As I discussed in my last post you can actually use multiple parameters within the functions you create, it is important to note that the parameters within a function are essentially like variables that can only be used within the function they are declared in. You can even reuse the name of parameters within your function as variables within your code without any issues.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p>def myName(name):<\/p>\n\n\n\n<p>    print(&#8220;My name is&#8221;, name)<\/p>\n\n\n\n<p>name = &#8220;John&#8221;<\/p>\n\n\n\n<p>myName(&#8220;Joseph&#8221;)<\/p>\n\n\n\n<p>print(name)<\/p>\n\n\n\n<p>Result:<\/p>\n\n\n\n<p>My name is Joseph<\/p>\n\n\n\n<p>John<\/p>\n\n\n\n<p>You can even have multiple parameters within the same function<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p>def sum_of_ABC(A, B, C):<\/p>\n\n\n\n<p>    print(A, &#8220;+&#8221;, B, &#8220;+&#8221;, C, &#8220;=&#8221;, A + B + C)<\/p>\n\n\n\n<p>sum_of_ABC(1, 2, 3)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Result:<\/p>\n\n\n\n<p>1 + 2 + 3 = 6<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>So what do you do if you have one parameter that is always going to remain the same? Well you can actually set that parameter within the function, it is important to note that if you are setting parameters within the function it will need to be done after all other positional parameters, example below.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>def name(firstName, lastName=&#8221;Gordon&#8221;):<\/p>\n\n\n\n<p>    print(&#8220;My name is&#8221;, firstName, lastName)<\/p>\n\n\n\n<p>name(&#8220;Joseph&#8221;, &#8220;Smith&#8221;)<\/p>\n\n\n\n<p>name(&#8220;Joseph&#8221;)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Result:<\/p>\n\n\n\n<p>My name is Joseph Smith<\/p>\n\n\n\n<p>My name is Joseph Gordon<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If the function was &#8220;def name(lastName=&#8221;Gordon&#8221;, firstName):&#8221; you would have received a syntax error. As always if there are any questions, feel free to reach out! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I discussed in my last post you can actually use multiple parameters within the functions you create, it is important to note that the parameters within a function are essentially like variables that can only be used within the function they are declared in. You can even reuse the name of parameters within your&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/245"}],"collection":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":2,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":327,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions\/327"}],"wp:attachment":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}