{"id":97,"date":"2024-08-27T10:17:54","date_gmt":"2024-08-27T10:17:54","guid":{"rendered":"https:\/\/techkubo.com\/python\/?p=97"},"modified":"2025-06-17T18:55:06","modified_gmt":"2025-06-17T18:55:06","slug":"python-functions","status":"publish","type":"post","link":"https:\/\/techkubo.com\/python\/python-functions\/","title":{"rendered":"Python Functions"},"content":{"rendered":"\n<p><style>\/*! elementor - v3.23.0 - 15-07-2024 *\/<br \/>\n.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]>a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}<\/style><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Functions?<\/h2>\n\n\n\n<p>A function is a block of code that performs a specific task. Functions are used to break up code into manageable pieces and to avoid repetition. Python comes with built-in functions like <code>print()<\/code> and <code>len()<\/code>, but you can also define your own.<\/p>\n\n\n\n<p>Example of a built-in function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">print(&quot;Hello, Philippines!&quot;)\u00a0 # This is a built-in function<\/pre><\/div>\n\n\n\n<p><style>\/*! elementor - v3.23.0 - 15-07-2024 *\/<br \/>\n.elementor-widget-divider{--divider-border-style:none;--divider-border-width:1px;--divider-color:#0c0d0e;--divider-icon-size:20px;--divider-element-spacing:10px;--divider-pattern-height:24px;--divider-pattern-size:20px;--divider-pattern-url:none;--divider-pattern-repeat:repeat-x}.elementor-widget-divider .elementor-divider{display:flex}.elementor-widget-divider .elementor-divider__text{font-size:15px;line-height:1;max-width:95%}.elementor-widget-divider .elementor-divider__element{margin:0 var(--divider-element-spacing);flex-shrink:0}.elementor-widget-divider .elementor-icon{font-size:var(--divider-icon-size)}.elementor-widget-divider .elementor-divider-separator{display:flex;margin:0;direction:ltr}.elementor-widget-divider--view-line_icon .elementor-divider-separator,.elementor-widget-divider--view-line_text .elementor-divider-separator{align-items:center}.elementor-widget-divider--view-line_icon .elementor-divider-separator:after,.elementor-widget-divider--view-line_icon .elementor-divider-separator:before,.elementor-widget-divider--view-line_text .elementor-divider-separator:after,.elementor-widget-divider--view-line_text .elementor-divider-separator:before{display:block;content:\"\";border-block-end:0;flex-grow:1;border-block-start:var(--divider-border-width) var(--divider-border-style) var(--divider-color)}.elementor-widget-divider--element-align-left .elementor-divider .elementor-divider-separator>.elementor-divider__svg:first-of-type{flex-grow:0;flex-shrink:100}.elementor-widget-divider--element-align-left .elementor-divider-separator:before{content:none}.elementor-widget-divider--element-align-left .elementor-divider__element{margin-left:0}.elementor-widget-divider--element-align-right .elementor-divider .elementor-divider-separator>.elementor-divider__svg:last-of-type{flex-grow:0;flex-shrink:100}.elementor-widget-divider--element-align-right .elementor-divider-separator:after{content:none}.elementor-widget-divider--element-align-right .elementor-divider__element{margin-right:0}.elementor-widget-divider--element-align-start .elementor-divider .elementor-divider-separator>.elementor-divider__svg:first-of-type{flex-grow:0;flex-shrink:100}.elementor-widget-divider--element-align-start .elementor-divider-separator:before{content:none}.elementor-widget-divider--element-align-start .elementor-divider__element{margin-inline-start:0}.elementor-widget-divider--element-align-end .elementor-divider .elementor-divider-separator>.elementor-divider__svg:last-of-type{flex-grow:0;flex-shrink:100}.elementor-widget-divider--element-align-end .elementor-divider-separator:after{content:none}.elementor-widget-divider--element-align-end .elementor-divider__element{margin-inline-end:0}.elementor-widget-divider:not(.elementor-widget-divider--view-line_text):not(.elementor-widget-divider--view-line_icon) .elementor-divider-separator{border-block-start:var(--divider-border-width) var(--divider-border-style) var(--divider-color)}.elementor-widget-divider--separator-type-pattern{--divider-border-style:none}.elementor-widget-divider--separator-type-pattern.elementor-widget-divider--view-line .elementor-divider-separator,.elementor-widget-divider--separator-type-pattern:not(.elementor-widget-divider--view-line) .elementor-divider-separator:after,.elementor-widget-divider--separator-type-pattern:not(.elementor-widget-divider--view-line) .elementor-divider-separator:before,.elementor-widget-divider--separator-type-pattern:not([class*=elementor-widget-divider--view]) .elementor-divider-separator{width:100%;min-height:var(--divider-pattern-height);-webkit-mask-size:var(--divider-pattern-size) 100%;mask-size:var(--divider-pattern-size) 100%;-webkit-mask-repeat:var(--divider-pattern-repeat);mask-repeat:var(--divider-pattern-repeat);background-color:var(--divider-color);-webkit-mask-image:var(--divider-pattern-url);mask-image:var(--divider-pattern-url)}.elementor-widget-divider--no-spacing{--divider-pattern-size:auto}.elementor-widget-divider--bg-round{--divider-pattern-repeat:round}.rtl .elementor-widget-divider .elementor-divider__text{direction:rtl}.e-con-inner>.elementor-widget-divider,.e-con>.elementor-widget-divider{width:var(--container-widget-width,100%);--flex-grow:var(--container-widget-flex-grow)}<\/style><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Defining a Function<\/h2>\n\n\n\n<p>You define a function in Python using the <code>def<\/code> keyword, followed by the function name, parentheses ( ), and a colon :. Inside the function, you write the block of code that will run when the function is called.<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def function_name():\n\u00a0\u00a0\u00a0\u00a0# Code to execute<\/pre><\/div>\n\n\n\n<p>Example:<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def welcome():\n\u00a0\u00a0\u00a0\u00a0print(&quot;Welcome to the Philippines!&quot;)<\/pre><\/div>\n\n\n\n<p>To call a function (i.e., execute the code within it), you simply use its name followed by parentheses:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def welcome():\n\u00a0\u00a0\u00a0\u00a0print(&quot;Welcome to the Philippines!&quot;)\n    \nwelcome()\u00a0 # Output: Welcome to the Philippines!<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Arguments and Parameters<\/h2>\n\n\n\n<p>Functions can accept arguments, which allow you to pass data into the function. When defining a function, the variables listed in the parentheses are called parameters. When calling the function, the actual values passed in are called arguments.<\/p>\n\n\n\n<p><b>Example<\/b>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def greet(name):\u00a0 # 'name' is the parameter\n \u00a0\u00a0\u00a0print(f&quot;Hello, {name}!&quot;)\n\ngreet(&quot;Maria&quot;)\u00a0 # 'Maria' is the argument<\/pre><\/div>\n\n\n\n<p><b style=\"font-weight: normal;\">&nbsp;<\/b><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Positional Arguments:&nbsp;<\/h3>\n\n\n\n<p>The arguments are passed in the order in which the parameters are defined.<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def add(x, y):\n\u00a0\u00a0\u00a0\u00a0return x + y\n\nresult = add(3, 5)\u00a0 # Arguments 3 and 5 are passed in positional order\nprint(result)\u00a0 # Output: 8<\/pre><\/div>\n\n\n\n<p><b style=\"font-weight: normal;\">&nbsp;<\/b><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Keyword Arguments:&nbsp;<\/h3>\n\n\n\n<p>You specify which argument corresponds to which parameter, regardless of their order.<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def add(x, y):\n\u00a0\u00a0\u00a0\u00a0return x + y\n\nresult = add(y=5, x=3)\u00a0 # Keyword arguments allow specifying values by their parameter names\nprint(result)\u00a0 # Output: 8<\/pre><\/div>\n\n\n\n<p><b style=\"font-weight: normal;\">&nbsp;<\/b><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Default Parameters:&nbsp;<\/h3>\n\n\n\n<p>You can set default values for parameters. If no argument is provided when the function is called, the default value will be used.<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def greet(name=&quot;Guest&quot;):\n\u00a0\u00a0\u00a0\u00a0print(f&quot;Hello, {name}!&quot;)\n\ngreet() \u00a0 \u00a0 \u00a0   # Output: Hello, Guest!\ngreet(&quot;Maria&quot;)\u00a0 # Output: Hello, Maria!<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">return Statement<\/h2>\n\n\n\n<p>The return statement allows a function to send a value back to the caller. This lets the function pass data back to the part of the program that called it. Once a return statement is executed, the function terminates.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">def add(x, y):\n\u00a0\u00a0\u00a0\u00a0return x + y\n\nresult = add(4, 5)\nprint(result)\u00a0 # Output: 9<\/pre><\/div>\n\n\n\n<p>A function without a return statement will return `None` by default.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Local vs Global Scope<\/h2>\n\n\n\n<p>The scope of a variable refers to the region of the code where that variable can be accessed. Variables defined inside a function are said to be in the local scope and can only be accessed within that function. Variables defined outside any function are in the global scope and can be accessed anywhere in the code.<\/p>\n\n\n\n<p>Example:<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">x = 10\u00a0 # Global variable\n\ndef example():\n \u00a0\u00a0\u00a0y = 5\u00a0 # Local variable\n \u00a0\u00a0\u00a0print(x)\u00a0 # Accessing global variable inside a function\n \u00a0\u00a0\u00a0print(y)\u00a0 # Accessing local variable\n\nexample()\nprint(x)\u00a0 # Output: 10\n# print(y) would raise an error, as y is not accessible outside the function<\/pre><\/div>\n\n\n\n<p>You can modify a global variable inside a function by using the global keyword, though it&#8217;s generally better practice to avoid this in most cases.<\/p>\n\n\n\n<p>Example:<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">x = 10\n\ndef modify_global():\n \u00a0\u00a0\u00a0global x\n \u00a0\u00a0\u00a0x = 20\n\nmodify_global()\n\nprint(x)\u00a0 # Output: 20<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Importing Modules<\/h2>\n\n\n\n<p>Modules are files containing Python code, which can include functions, variables, and classes. You can import a module into your script using the `import` keyword, which gives you access to its functionality.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import math\u00a0 # Importing the math module\n\nprint(math.sqrt(16))\u00a0 # Using a function from the math module, Output: 4.0<\/pre><\/div>\n\n\n\n<p>You can also import specific functions or objects from a module:<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">from math import sqrt\n\nprint(sqrt(25))\u00a0 # Output: 5.0<\/pre><\/div>\n\n\n\n<p>To give an imported module a custom name (an alias):<b style=\"font-weight: normal;\"><\/b><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;seti&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Python&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import math as m\n\nprint(m.pi)\u00a0 # Output: 3.141592653589793<\/pre><\/div>\n\n\n\n<p>Modules make it easy to reuse code across different programs, and Python comes with a large standard library of built-in modules.<\/p>\n\n\n\n<p><iframe title=\"Try Python on TechKubo\" src=\"https:\/\/techkubo.com\/python-sim.html\" width=\"100%\" height=\"500\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are Functions? A function is a block of code that performs a specific task. Functions are used to break [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Functions - Python Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techkubo.com\/python\/python-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Functions - Python Tutorial\" \/>\n<meta property=\"og:description\" content=\"What are Functions? A function is a block of code that performs a specific task. Functions are used to break [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techkubo.com\/python\/python-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-27T10:17:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-17T18:55:06+00:00\" \/>\n<meta name=\"author\" content=\"Manong\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/\"},\"author\":{\"name\":\"Manong\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\"},\"headline\":\"Python Functions\",\"datePublished\":\"2024-08-27T10:17:54+00:00\",\"dateModified\":\"2025-06-17T18:55:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/\"},\"wordCount\":430,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/python\/#organization\"},\"articleSection\":[\"python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techkubo.com\/python\/python-functions\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/\",\"url\":\"https:\/\/techkubo.com\/python\/python-functions\/\",\"name\":\"Python Functions - Python Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/python\/#website\"},\"datePublished\":\"2024-08-27T10:17:54+00:00\",\"dateModified\":\"2025-06-17T18:55:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techkubo.com\/python\/python-functions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techkubo.com\/python\/python-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techkubo.com\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techkubo.com\/python\/#website\",\"url\":\"https:\/\/techkubo.com\/python\/\",\"name\":\"Python Tutorial\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techkubo.com\/python\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techkubo.com\/python\/#organization\",\"name\":\"Python Tutorial\",\"url\":\"https:\/\/techkubo.com\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png\",\"width\":1620,\"height\":1156,\"caption\":\"Python Tutorial\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\",\"name\":\"Manong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/python\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"caption\":\"Manong\"},\"sameAs\":[\"https:\/\/techkubo.com\"],\"url\":\"https:\/\/techkubo.com\/python\/author\/manong\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Functions - Python Tutorial","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:\/\/techkubo.com\/python\/python-functions\/","og_locale":"en_US","og_type":"article","og_title":"Python Functions - Python Tutorial","og_description":"What are Functions? A function is a block of code that performs a specific task. Functions are used to break [&hellip;]","og_url":"https:\/\/techkubo.com\/python\/python-functions\/","og_site_name":"Python Tutorial","article_published_time":"2024-08-27T10:17:54+00:00","article_modified_time":"2025-06-17T18:55:06+00:00","author":"Manong","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manong","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techkubo.com\/python\/python-functions\/#article","isPartOf":{"@id":"https:\/\/techkubo.com\/python\/python-functions\/"},"author":{"name":"Manong","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965"},"headline":"Python Functions","datePublished":"2024-08-27T10:17:54+00:00","dateModified":"2025-06-17T18:55:06+00:00","mainEntityOfPage":{"@id":"https:\/\/techkubo.com\/python\/python-functions\/"},"wordCount":430,"commentCount":0,"publisher":{"@id":"https:\/\/techkubo.com\/python\/#organization"},"articleSection":["python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techkubo.com\/python\/python-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techkubo.com\/python\/python-functions\/","url":"https:\/\/techkubo.com\/python\/python-functions\/","name":"Python Functions - Python Tutorial","isPartOf":{"@id":"https:\/\/techkubo.com\/python\/#website"},"datePublished":"2024-08-27T10:17:54+00:00","dateModified":"2025-06-17T18:55:06+00:00","breadcrumb":{"@id":"https:\/\/techkubo.com\/python\/python-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techkubo.com\/python\/python-functions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/techkubo.com\/python\/python-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techkubo.com\/python\/"},{"@type":"ListItem","position":2,"name":"Python Functions"}]},{"@type":"WebSite","@id":"https:\/\/techkubo.com\/python\/#website","url":"https:\/\/techkubo.com\/python\/","name":"Python Tutorial","description":"","publisher":{"@id":"https:\/\/techkubo.com\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techkubo.com\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techkubo.com\/python\/#organization","name":"Python Tutorial","url":"https:\/\/techkubo.com\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/","url":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png","contentUrl":"https:\/\/techkubo.com\/python\/wp-content\/uploads\/sites\/2\/2025\/01\/cropped-Techkubo-logo-1.png","width":1620,"height":1156,"caption":"Python Tutorial"},"image":{"@id":"https:\/\/techkubo.com\/python\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965","name":"Manong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/python\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","caption":"Manong"},"sameAs":["https:\/\/techkubo.com"],"url":"https:\/\/techkubo.com\/python\/author\/manong\/"}]}},"_links":{"self":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/97"}],"collection":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":14,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/posts\/97\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techkubo.com\/python\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}