{"id":451,"date":"2025-05-20T04:51:26","date_gmt":"2025-05-20T04:51:26","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=451"},"modified":"2026-06-06T11:34:52","modified_gmt":"2026-06-06T11:34:52","slug":"functions","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/python\/functions\/","title":{"rendered":"Functions"},"content":{"rendered":"<h2><strong>Defining and calling functions<\/strong><span style=\"font-weight: 400\"><br \/>\n<\/span><\/h2>\n<p><strong>What Are Functions?<\/strong><\/p>\n<p>A function is a block of reusable code that performs a specific task. You define functions to avoid repeating code, enhance readability, and make your code more modular. In Python tutorials such as <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python course\">Introduction to Python<\/a>, you&#8217;ll see these concepts demonstrated.<\/p>\n<h3>1. Defining a Function<\/h3>\n<p>To define a function, you use the def keyword followed by the function name, parentheses, and a colon (:). The indented code that follows is the body of the function, where the logic happens.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name(parameters):<\/em><br \/>\n<em># function body<\/em><br \/>\n<em># code to be executed<\/em><\/p>\n<p><strong>Example 1:<\/strong> A Simple Function<\/p>\n<p style=\"text-align: center\"><em>def greet():<\/em><br \/>\n<em>print(&#8220;Hello, welcome!&#8221;)<\/em><\/p>\n<ul>\n<li>def defines the function.<\/li>\n<li>greet() is the function name.<\/li>\n<li>The body contains the print() statement.<\/li>\n<\/ul>\n<p>This function doesn\u2019t accept any parameters and simply prints a message when called.<\/p>\n<h3>2. Calling a Function<\/h3>\n<p>After defining a function, you can call it by using its name followed by parentheses. This behavior is explored in more depth in the <a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">Functions and Scope<\/a> lesson.<\/p>\n<h3>3. Functions with Parameters<\/h3>\n<p>Functions can accept parameters \u2014 values that are passed into the function when it\u2019s called. For a deeper look at parameters and how they relate to scope, see <a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">Functions and Scope<\/a>.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name(parameter1, parameter2):<\/em><br \/>\n<em># code<\/em><\/p>\n<p><strong>Example 3:<\/strong> Function with Parameters<\/p>\n<p style=\"text-align: center\"><em>def greet(name):<\/em><br \/>\n<em>print(f&#8221;Hello, {name}!&#8221;)<\/em><\/p>\n<p><strong>Calling the Function with an Argument<\/strong><\/p>\n<p style=\"text-align: center\"><em>greet(&#8220;Alice&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>Hello, Alice!<\/em><\/p>\n<p>The function greet() accepts a name parameter and prints a personalized greeting.<\/p>\n<h3>4. Functions with Return Values<\/h3>\n<p>Functions can return a value using the return keyword, allowing you to send results back to where the function was called.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name():<\/em><br \/>\n<em>return value<\/em><\/p>\n<p><strong>Example 4:<\/strong> Function with a Return Value<\/p>\n<p style=\"text-align: center\"><em>def add(a, b):<\/em><br \/>\n<em>return a + b<\/em><\/p>\n<p><strong> Calling the Function and Using the Return Value<\/strong><\/p>\n<p style=\"text-align: center\"><em>result = add(5, 3)<\/em><br \/>\n<em>print(result)<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>8<\/em><\/p>\n<p>The add() function returns the sum of a and b, and the result is stored in the result variable, which is then printed. This pattern of computing and returning results is common in many real-world tasks.<\/p>\n<h3>5. Functions with Multiple Parameters and Default Values<\/h3>\n<p>Functions can also have default parameters, meaning that if no value is passed for them, a default value will be used.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name(param1, param2=default_value):<\/em><br \/>\n<em># code<\/em><\/p>\n<p><strong>Example 5:<\/strong> Function with a Default Parameter<\/p>\n<p style=\"text-align: center\"><em>def greet(name, greeting=&#8221;Hello&#8221;):<\/em><br \/>\n<em>print(f&#8221;{greeting}, {name}!&#8221;)<\/em><\/p>\n<p><strong> Calling the Function with and without Default Parameter<\/strong><\/p>\n<p style=\"text-align: center\"><em>greet(&#8220;Bob&#8221;) # Uses default greeting<\/em><br \/>\n<em>greet(&#8220;Alice&#8221;, &#8220;Good morning&#8221;) # Custom greeting<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p style=\"text-align: center\"><em>Hello, Bob!<\/em><br \/>\n<em>Good morning, Alice!<\/em><\/p>\n<p><strong>Summary of Key Points:<\/strong><\/p>\n<ul>\n<li>Defining a function: Use def followed by the function name and parameters.<\/li>\n<li>Calling a function: Simply write the function name followed by parentheses.<\/li>\n<li>Parameters: Functions can accept inputs (parameters) to customize their behavior.<\/li>\n<li>Return values: Use return to send results from a function back to the caller.<\/li>\n<li>Default values: Parameters can have default values in case no argument is provided.<\/li>\n<\/ul>\n<p><strong>Example of Multiple Concepts:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def multiply(a, b=2):<\/em><br \/>\n<em>return a * b<\/em><\/p>\n<p style=\"text-align: center\"><em>result1 = multiply(5) # Uses default value for b<\/em><br \/>\n<em>result2 = multiply(5, 3) # Custom value for b<\/em><\/p>\n<p style=\"text-align: center\"><em>print(result1) # Output: 10<\/em><br \/>\n<em>print(result2) # Output: 15<\/em><\/p>\n<h2>Parameters, arguments, and return values<\/h2>\n<h3>1. Parameters<\/h3>\n<p><span style=\"font-size: 1.25rem\">Parameters are variables that are defined in a function\u2019s signature (the function definition). They act as placeholders for values that are passed into the function when it is called.<\/span><\/p>\n<p>Parameters let you write generic, reusable functions that can handle different inputs.<\/p>\n<p><strong>Syntax for Parameters:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name(parameter1, parameter2):<\/em><br \/>\n<em># function body<\/em><\/p>\n<p><strong>Example:<\/strong> Parameters in Action<\/p>\n<p style=\"text-align: center\"><em>def greet(name, greeting=&#8221;Hello&#8221;):<\/em><br \/>\n<em>print(f&#8221;{greeting}, {name}!&#8221;)<\/em><\/p>\n<ul>\n<li>name and greeting are parameters.<\/li>\n<li>greeting has a default value (&#8220;Hello&#8221;), so it&#8217;s optional when calling the function.<\/li>\n<\/ul>\n<p><strong>Key Points:<\/strong><\/p>\n<ul>\n<li>Parameters define the inputs a function requires.<\/li>\n<li>Parameters are used within the function body.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> For a deeper dive into parameters and how they interact with scope, see <a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">Functions and Scope<\/a>.<\/p>\n<h3>2. Arguments<\/h3>\n<p>Arguments are the actual values that you pass into a function when you call it. The function receives arguments and uses them to perform its tasks. Arguments are provided in the function call and match the function\u2019s parameters in order. For more context, the <a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">Functions and Scope<\/a> lesson covers how arguments map to parameters.<\/p>\n<p><strong>Syntax for Arguments:<\/strong><\/p>\n<p style=\"text-align: center\"><em>function_name(argument1, argument2)<\/em><\/p>\n<p><strong>Example:<\/strong> Passing Arguments<\/p>\n<p style=\"text-align: center\"><em>greet(&#8220;Alice&#8221;, &#8220;Good morning&#8221;)<\/em><\/p>\n<ul>\n<li>&#8220;Alice&#8221; and &#8220;Good morning&#8221; are arguments.<\/li>\n<li>&#8220;Alice&#8221; is passed to the name parameter, and &#8220;Good morning&#8221; is passed to the greeting parameter.<\/li>\n<\/ul>\n<p><strong>Key Points:<\/strong><\/p>\n<ul>\n<li>Arguments are the real values passed to the function when it is called.<\/li>\n<li>Arguments replace parameters with actual data.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> You can also use keyword arguments for clarity; see Introduction to Python for more examples.<\/p>\n<h3>3. Return Values<\/h3>\n<p>A return value is the result that a function sends back after it completes its task. A function can return any kind of value \u2014 numbers, strings, lists, etc.<\/p>\n<p>The return keyword is used to send a value back from a function. Once return is executed, the function exits, and the returned value can be used or stored outside of the function.<\/p>\n<p><strong>Syntax for Return Values:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def function_name():<\/em><br \/>\n<em>return value<\/em><\/p>\n<p><strong>Example:<\/strong> Function with Return Value<\/p>\n<p style=\"text-align: center\"><em>def add(a, b):<\/em><br \/>\n<em>return a + b<\/em><\/p>\n<ul>\n<li>The add() function returns the sum of a and b.<\/li>\n<li>When the function finishes, it sends the result back to the caller.<\/li>\n<\/ul>\n<p><strong>Key Points:<\/strong><\/p>\n<ul>\n<li>A function can return a value using return.<\/li>\n<li>The function stops executing after a return statement.<\/li>\n<\/ul>\n<p><strong>Example of Using Parameters, Arguments, and Return Value Together:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def multiply(a, b=1):<\/em><br \/>\n<em>return a * b<\/em><\/p>\n<p style=\"text-align: center\"><em># Calling the function with arguments:<\/em><br \/>\n<em>result1 = multiply(5) # Uses default b=1<\/em><br \/>\n<em>result2 = multiply(5, 3) # Custom b=3<\/em><\/p>\n<p style=\"text-align: center\"><em>print(result1) # Output: 5 (5 * 1)<\/em><br \/>\n<em>print(result2) # Output: 15 (5 * 3)<\/em><\/p>\n<ul>\n<li>Parameters: a and b are defined in the function signature.<\/li>\n<li>Arguments: 5 and 3 are passed when calling the function.<\/li>\n<li>Return Value: The result of a * b is returned and stored in result1 and result2.<\/li>\n<\/ul>\n<p><strong>Key Takeaways:<\/strong><\/p>\n<ul>\n<li>Parameters: Variables defined in the function to receive inputs.<\/li>\n<li>Arguments: Values passed to the function when calling it (matching parameters).<\/li>\n<li>Return Values: The result that the function sends back after completing its task, allowing you to use the output outside the function.<\/li>\n<\/ul>\n<p>For more practice with parameters, arguments, and return values, explore the <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python course\">Introduction to Python<\/a> and <a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">Functions and Scope<\/a> resources.<\/p>\n<h2>Variable scope<\/h2>\n<h3>What is Variable Scope?<\/h3>\n<p>Variable scope refers to the region of a program where a variable can be accessed. In Python, the scope is influenced by where the variable is declared and where it is used.<\/p>\n<p><strong>Types of Scope in Python<\/strong><\/p>\n<ul>\n<li>Local Scope<\/li>\n<li>Enclosing Scope<\/li>\n<li>Global Scope<\/li>\n<li>Built-in Scope<\/li>\n<\/ul>\n<h3>1. Local Scope<\/h3>\n<p>A variable has local scope if it is defined inside a function or a block of code. This means it is only accessible within that function or block.<\/p>\n<ul>\n<li>Local variables are created when the function is called and destroyed when the function finishes execution.<\/li>\n<\/ul>\n<p><strong>Example of Local Scope:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def my_function():<\/em><br \/>\n<em>x = 10 # x is local to my_function<\/em><br \/>\n<em>print(x)<\/em><\/p>\n<p style=\"text-align: center\"><em>my_function() # Output: 10<\/em><br \/>\n<em># print(x) # This would cause an error because x is local to my_function<\/em><\/p>\n<p>In the example, x is local to my_function(), and trying to access x outside the function will raise a NameError.<\/p>\n<h3>2. Enclosing Scope (Nonlocal)<\/h3>\n<p>Enclosing scope refers to the scope of a function within another function. Variables defined in the outer (enclosing) function are accessible to the inner (nested) function.<\/p>\n<ul>\n<li>These variables are not local to the inner function but can be modified using the nonlocal keyword.<\/li>\n<\/ul>\n<p><strong>Example of Enclosing Scope:<\/strong><\/p>\n<p style=\"text-align: center\"><em>def outer_function():<\/em><br \/>\n<em>x = 20 # x is in the enclosing scope<\/em><br \/>\n<em>def inner_function():<\/em><br \/>\n<em>print(x) # Can access x from the enclosing function<\/em><br \/>\n<em>inner_function()<\/em><\/p>\n<p style=\"text-align: center\"><em>outer_function() # Output: 20<\/em><\/p>\n<p>Here, inner_function() can access x from the outer_function() because x is in an enclosing scope.<\/p>\n<h3>3. Global Scope<\/h3>\n<p>A variable has global scope if it is defined at the top level of the script or module (outside any function). Global variables can be accessed from any part of the program, including inside functions (but not always modified directly without the global keyword).<\/p>\n<ul>\n<li>Global variables exist throughout the life of the program.<\/li>\n<\/ul>\n<p><strong>Example of Global Scope:<\/strong><\/p>\n<p style=\"text-align: center\"><em>x = 50 # x is a global variable<\/em><\/p>\n<p style=\"text-align: center\"><em>def my_function():<\/em><br \/>\n<em>print(x) # Can access global x inside the function<\/em><\/p>\n<p style=\"text-align: center\"><em>my_function() # Output: 50<\/em><br \/>\n<em>print(x) # Output: 50<\/em><\/p>\n<p>In this example, x is defined in the global scope and can be accessed inside the function my_function().<\/p>\n<p><strong>Modifying a Global Variable:<\/strong><\/p>\n<p>To modify a global variable inside a function, use the global keyword:<\/p>\n<p style=\"text-align: center\"><em>x = 50 # Global variable<\/em><\/p>\n<p style=\"text-align: center\"><em>def my_function():<\/em><br \/>\n<em>global x<\/em><br \/>\n<em>x = 100 # Modifies the global x<\/em><\/p>\n<p style=\"text-align: center\"><em>my_function()<\/em><br \/>\n<em>print(x) # Output: 100<\/em><\/p>\n<p>Without the global keyword, trying to assign to x inside the function would create a local variable x instead of modifying the global one.<\/p>\n<h3>4. Built-in Scope<\/h3>\n<p>Built-in scope refers to the names that are available in Python\u2019s built-in namespace, which includes functions like print(), len(), sum(), and more. These names are available throughout the entire program.<\/p>\n<ul>\n<li>Built-in variables and functions are part of Python&#8217;s core language and are always accessible.<\/li>\n<\/ul>\n<p><strong>Example of Built-in Scope:<\/strong><\/p>\n<p style=\"text-align: center\"><em>print(len(&#8220;Hello&#8221;)) # &#8216;len&#8217; is a built-in function<\/em><\/p>\n<p>In this example, print() and len() are built-in functions, available globally without needing to be imported or defined.<\/p>\n<p><strong>LEGB Rule (Local, Enclosing, Global, Built-in)<\/strong><\/p>\n<p>When you reference a variable, Python follows the LEGB rule to look for it:<\/p>\n<ul>\n<li>Local: First, Python looks for the variable in the local function scope.<\/li>\n<li>Enclosing: If it&#8217;s not found, Python checks in any enclosing functions (from outer to inner).<\/li>\n<li>Global: If it\u2019s not found in enclosing scopes, Python searches for the variable in the global scope.<\/li>\n<li>Built-in: If the variable is still not found, Python checks the built-in scope for the variable.<\/li>\n<\/ul>\n<p><strong>Example of LEGB Rule:<\/strong><\/p>\n<p style=\"text-align: center\"><em>x = 5 # Global variable<\/em><\/p>\n<p style=\"text-align: center\"><em>def outer_function():<\/em><br \/>\n<em>x = 10 # Enclosing variable<\/em><br \/>\n<em><a href=\"https:\/\/buhave.com\/courses\/java-script\/functions-and-scope\/\" title=\"Functions and Scope course\">LEGB rule<\/a> is used to resolve references<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Defining and calling functions What Are Functions? A function is a block of reusable code that performs a specific task. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":768,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","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":"","ast-disable-related-posts":"","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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Functions - Python Course<\/title>\n<meta name=\"description\" content=\"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/python\/functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Functions - Python Course\" \/>\n<meta property=\"og:description\" content=\"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/python\/functions\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T04:51:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-06T11:34:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"Functions\",\"datePublished\":\"2025-05-20T04:51:26+00:00\",\"dateModified\":\"2026-06-06T11:34:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/\"},\"wordCount\":1598,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Functions.webp\",\"articleSection\":[\"Python Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/\",\"name\":\"Functions - Python Course\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Functions.webp\",\"datePublished\":\"2025-05-20T04:51:26+00:00\",\"dateModified\":\"2026-06-06T11:34:52+00:00\",\"description\":\"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Functions.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Functions.webp\",\"width\":1200,\"height\":628,\"caption\":\"Functions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Functions - Python Course","description":"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.","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:\/\/buhave.com\/courses\/python\/functions\/","og_locale":"en_US","og_type":"article","og_title":"Functions - Python Course","og_description":"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.","og_url":"https:\/\/buhave.com\/courses\/python\/functions\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-20T04:51:26+00:00","article_modified_time":"2026-06-06T11:34:52+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/python\/functions\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"Functions","datePublished":"2025-05-20T04:51:26+00:00","dateModified":"2026-06-06T11:34:52+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/"},"wordCount":1598,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp","articleSection":["Python Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/python\/functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/python\/functions\/","url":"https:\/\/buhave.com\/courses\/python\/functions\/","name":"Functions - Python Course","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp","datePublished":"2025-05-20T04:51:26+00:00","dateModified":"2026-06-06T11:34:52+00:00","description":"Functions are reusable blocks of code that perform specific tasks when called; they help organize code and avoid repetition.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/python\/functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/python\/functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/python\/functions\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Functions.webp","width":1200,"height":628,"caption":"Functions"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/python\/functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Python Course","item":"https:\/\/buhave.com\/courses\/learn\/python\/"},{"@type":"ListItem","position":3,"name":"Functions"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":2,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/451\/revisions\/1121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/768"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}