{"id":242,"date":"2023-04-04T04:15:47","date_gmt":"2023-04-04T04:15:47","guid":{"rendered":"https:\/\/joseph-t-gordon.tech\/?p=242"},"modified":"2023-06-26T14:24:16","modified_gmt":"2023-06-26T14:24:16","slug":"post-42-functions-in-python","status":"publish","type":"post","link":"https:\/\/joseph-t-gordon.tech\/index.php\/2023\/04\/04\/post-42-functions-in-python\/","title":{"rendered":"Post #42 (Python Programming) &#8211; Functions in python"},"content":{"rendered":"\n<p>Let&#8217;s say you have a piece of code that is repeated multiple times in your program like so.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p>print(&#8220;I have a message&#8221;)<\/p>\n\n\n\n<p>print(&#8220;I have a message&#8221;)<\/p>\n\n\n\n<p>print(&#8220;I have a message&#8221;)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Now if you want to change your message you will need to change each instance of it, you can avoid this by creating a function, a function allows you to create a set of code to be ran every time the function is called you use def to create a function like so<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<p>def firstFunction():<\/p>\n\n\n\n<p>    print(&#8220;I have a message&#8221;)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>firstFunction()<\/p>\n\n\n\n<p>firstFunction()<\/p>\n\n\n\n<p>firstFunction()<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Now if you want to change the message you simply need to alter the function&#8217;s code. You can even add further parameters to the function to be used, I will go into further detail on that in my next post!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you have a piece of code that is repeated multiple times in your program like so. Code: print(&#8220;I have a message&#8221;) print(&#8220;I have a message&#8221;) print(&#8220;I have a message&#8221;) Now if you want to change your message you will need to change each instance of it, you can avoid this by creating a&#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\/242"}],"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=242"}],"version-history":[{"count":2,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}