{"id":4232,"date":"2022-03-08T15:03:44","date_gmt":"2022-03-08T15:03:44","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4232"},"modified":"2025-12-17T18:43:43","modified_gmt":"2025-12-17T18:43:43","slug":"functions-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/functions\/functions-general","title":{"rendered":".Functions general"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>def my_function_name():\n  #Function code\n\n\n\/\/Calling it\nmy_function_name()<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Using Parameters<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>def my_function_name(my_variable1, my_variable2):\n  #Function code\n\ndef my_function_name(my_variable1,\n  my_variable2\n):\n  #Function code\n\n\/\/Calling it\nmy_function_name(21, \"abc\")\n\n\/\/Calling it specifying the parameter names\nmy_function_name(my_variable1=21, my_variable2=\"abc\")\nmy_function_name(my_variable2=\"abc\", my_variable1=21)<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Default values<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>def my_function_name(my_variable1, my_variable2=\"abc\"):\n  #Function code\n\n\/\/Calling it\nmy_function_name(21)\nmy_function_name(21, \"def\")\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Defining parameter types<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>def my_function_name(my_variable1: int,\n  my_variable2: int = 20\n):\n  #Function code<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Return values<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>def my_function_name():\n  return 21\n\n\/\/Calling it\nreturn_value = my_function_name()<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Multiple return values<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>def my_function_name():\n  return 21, \"abc\", 55\n\n\/\/Calling it\nreturn_value_1, return_value_2, return_value_3 = my_function_name()<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Using a dictionary for multiple return values<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#In the function:\n    if something == True:\n        return_values = {}\n        return_values&#91;'Something1'] = \"abc\"\n        return_values&#91;'Something2'] = \"def\"\n        return_values&#91;'Something3'] = \"ghi\"\n        return return_values\n\n    return False\n\n#Calling it\n    return_value = my_function(camera_serial_number)\n    if return_value != False:\n        #### = return_value&#91;'Something2']\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using Parameters Default values Defining parameter types Return values Multiple return values Using a dictionary for multiple return values<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[335],"tags":[],"class_list":["post-4232","post","type-post","status-publish","format-standard","hentry","category-functions"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4232"}],"version-history":[{"count":12,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4232\/revisions"}],"predecessor-version":[{"id":4982,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4232\/revisions\/4982"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}