{"id":235031,"date":"2025-11-24T12:50:23","date_gmt":"2025-11-24T17:50:23","guid":{"rendered":"https:\/\/ibkrcampus.com\/campus\/?p=235031"},"modified":"2025-11-24T12:51:06","modified_gmt":"2025-11-24T17:51:06","slug":"python-functions-definition-scope-and-returns","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/","title":{"rendered":"Python Functions: Definition, Scope, and Returns"},"content":{"rendered":"\n<p><em>The article &#8220;Python Functions: Definition, Scope, and Returns&#8221; was originally posted on <a href=\"https:\/\/www.pyquantnews.com\/free-python-resources\/python-functions-definition-scope-and-returns\">PyQuant News.<\/a><\/em><\/p>\n\n\n\n<p>Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation. An essential concept in Python is understanding functions, which include defining, calling, and working with their scope and return values. This guide is tailored for both beginners and experienced developers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-defining-functions-in-python\">Defining Functions in Python<\/h3>\n\n\n\n<p>In Python, defining a function starts with the&nbsp;<code>def<\/code>&nbsp;keyword, followed by the function name and parentheses with any parameters. Here&#8217;s a simple example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def greet(name):\n   print(f\"Hello, {name}!\")<\/pre>\n\n\n\n<p>This&nbsp;<code>greet<\/code>&nbsp;function takes a&nbsp;<code>name<\/code>&nbsp;parameter and prints a greeting. Python functions can handle multiple parameters, default parameters, and even a variable number of arguments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Multiple Parameters<\/h4>\n\n\n\n<p>A function can accept multiple parameters for more complex operations:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def add(a, b):\n   return a + b<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Default Parameters<\/h4>\n\n\n\n<p>Default parameters allow you to set a default value for a parameter if no argument is provided during the function call:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def greet(name=\"World\"):\n   print(f\"Hello, {name}!\")<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Variable Number of Arguments<\/h4>\n\n\n\n<p>Python supports functions that can accept a variable number of positional arguments using&nbsp;<code>*args<\/code>&nbsp;and keyword arguments using&nbsp;<code>**kwargs<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def print_names(*args):\n   for name in args:\n       print(name)\n\ndef print_dict(**kwargs):\n   for key, value in kwargs.items():\n       print(f\"{key}: {value}\")<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Calling Functions<\/h3>\n\n\n\n<p>Once a function is defined, you can call it using its name followed by parentheses containing any arguments:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">greet(\"Alice\")\nresult = add(5, 3)\nprint(result)\nprint_names(\"John\", \"Jane\", \"Doe\")\nprint_dict(a=1, b=2, c=3)<\/pre>\n\n\n\n<p>You can also nest function calls, allowing one function to call another during its execution:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def square(x):\n   return x * x\n\ndef sum_of_squares(a, b):\n   return square(a) + square(b)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding Scope in Python Functions<\/h3>\n\n\n\n<p>Scope in Python functions defines where a particular variable is accessible. Variables can have either local or global scope.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Local Scope<\/h4>\n\n\n\n<p>Variables defined inside a function have local scope and are only accessible within that function:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def foo():\n   x = 10  # x is a local variable\n   print(x)\n\nfoo()\nprint(x)  # This will raise a NameError<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Global Scope<\/h4>\n\n\n\n<p>Variables defined outside a function have global scope and can be accessed anywhere in the code:<\/p>\n\n\n\n<p><code>x = 10 &nbsp;# x is a global variable<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def foo():\n   print(x)\n\nfoo()\nprint(x)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">The&nbsp;<code>global<\/code>&nbsp;Keyword<\/h4>\n\n\n\n<p>To modify a global variable inside a function, use the&nbsp;<code>global<\/code>&nbsp;keyword:<\/p>\n\n\n\n<p><code>x = 10<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def foo():\n   global x\n   x = 20\n\nfoo()\nprint(x)  # This will print 20<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Return Values in Python Functions<\/h3>\n\n\n\n<p>Functions can return values using the&nbsp;<code>return<\/code>&nbsp;keyword, enabling you to use the function&#8217;s output elsewhere in your code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def add(a, b):\n   return a + b\n\nresult = add(5, 3)\nprint(result)  # This will print 8<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Returning Multiple Values<\/h4>\n\n\n\n<p>Python functions can return multiple values, typically as a tuple:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def get_coordinates():\n   x = 10\n   y = 20\n   return x, y\n\nx, y = get_coordinates()\nprint(x, y)  # This will print 10 20<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">No Return Statement<\/h4>\n\n\n\n<p>If a function lacks a return statement, it returns&nbsp;<code>None<\/code>&nbsp;by default:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def foo():\n   pass\n\nresult = foo()\nprint(result)  # This will print None<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Function Concepts<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Lambda Functions<\/h4>\n\n\n\n<p>Lambda functions, or anonymous functions, are concise, single-expression functions defined using the&nbsp;<code>lambda<\/code>&nbsp;keyword:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add = lambda a, b: a + b\nprint(add(5, 3))  # This will print 8<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Decorators<\/h4>\n\n\n\n<p>Decorators modify the behavior of a function and are used for logging, access control, and memoization:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def decorator_function(original_function):\n   def wrapper_function(*args, **kwargs):\n       print(f\"Calling {original_function.__name__}\")\n       return original_function(*args, **kwargs)\n   return wrapper_function\n\n@decorator_function\ndef greet(name):\n   print(f\"Hello, {name}!\")\n\ngreet(\"Alice\")<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Higher-Order Functions<\/h4>\n\n\n\n<p>Higher-order functions either take another function as an argument or return a function as a result. Common examples include&nbsp;<code>map<\/code>,&nbsp;<code>filter<\/code>, and&nbsp;<code>reduce<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def square(x):\n   return x * x\n\nnumbers = [1, 2, 3, 4, 5]\nsquared_numbers = map(square, numbers)\nprint(list(squared_numbers))  # This will print [1, 4, 9, 16, 25]<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Debugging Python Functions<\/h3>\n\n\n\n<p>Debugging functions is a vital skill for any programmer. Python offers several tools and techniques to help debug your code effectively.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Print Statements<\/h4>\n\n\n\n<p>Using print statements to display variable values at different points in the code is a simple way to debug:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def add(a, b):\n   print(f\"a: {a}, b: {b}\")\n   return a + b\n\nresult = add(5, 3)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">The&nbsp;<code>pdb<\/code>&nbsp;Module<\/h4>\n\n\n\n<p>The Python Debugger (<code>pdb<\/code>) allows you to set breakpoints, step through your code, and inspect variables interactively:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pdb\n\ndef add(a, b):\n   pdb.set_trace()\n   return a + b\n\nresult = add(5, 3)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">IDE Debugging Tools<\/h4>\n\n\n\n<p>Modern Integrated Development Environments (IDEs) like PyCharm, VSCode, and Jupyter notebooks come with built-in debugging tools that simplify the debugging process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Best Practices for Writing Python Functions<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Keep Functions Small and Focused<\/h4>\n\n\n\n<p>A function should perform a single task or a closely related set of tasks, making it easier to understand, test, and maintain.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Use Descriptive Names<\/h4>\n\n\n\n<p>The function name should clearly describe what it does, enhancing code readability:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def calculate_total_price(price, tax_rate):\n   return price + (price * tax_rate)<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def calculate_total_price(price, tax_rate):\n   return price + (price * tax_rate)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Write Docstrings<\/h4>\n\n\n\n<p>Docstrings provide a description of what the function does, its parameters, and its return values:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def add(a, b):\n   \"\"\"\n   Adds two numbers and returns the result.\n\n   Parameters:\n   a (int or float): The first number.\n   b (int or float): The second number.\n\n   Returns:\n   int or float: The sum of a and b.\n   \"\"\"\n   return a + b<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Handle Errors Gracefully<\/h4>\n\n\n\n<p>Use try-except blocks to handle potential errors:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def divide(a, b):\n   try:\n       return a \/ b\n   except ZeroDivisionError:\n       return \"Division by zero is not allowed.\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Resources for Further Learning<\/h3>\n\n\n\n<p>For more on Python functions and advanced topics, consider:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>&#8220;Automate the Boring Stuff with Python&#8221; by Al Sweigart<\/strong>: An excellent resource for practical Python applications.<\/li>\n\n\n\n<li><strong>&#8220;Python Crash Course&#8221; by Eric Matthes<\/strong>: A comprehensive introduction to Python programming.<\/li>\n\n\n\n<li><strong>Real Python<\/strong>: Offers tutorials, articles, and guides on various Python topics.<\/li>\n\n\n\n<li><strong>Python Documentation<\/strong>: A valuable resource for understanding Python functions.<\/li>\n\n\n\n<li><strong>Coursera and edX Courses<\/strong>: Online platforms offering Python programming courses taught by university professors.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Understanding how to define, call, and work with Python functions, including their scope and return values, is fundamental for writing modular, reusable, and maintainable code. Whether a beginner or an experienced developer, mastering Python functions is a key step in your programming journey. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation. <\/p>\n","protected":false},"author":1518,"featured_media":196081,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":true,"footnotes":""},"categories":[339,343,349,338,341],"tags":[806,6614,11708,595,20525],"contributors-categories":[17813],"class_list":{"0":"post-235031","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-python-development","10":"category-ibkr-quant-news","11":"category-quant-development","12":"tag-data-science","13":"tag-jupyter-notebook","14":"tag-pycharm","15":"tag-python","16":"tag-vscode","17":"contributors-categories-pyquantnews"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Functions: Definition, Scope, and Returns<\/title>\n<meta name=\"description\" content=\"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/235031\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Functions: Definition, Scope, and Returns\" \/>\n<meta property=\"og:description\" content=\"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-24T17:50:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-24T17:51:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jason\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Jason\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/41e9bacc875edb13ed6288f4ffb2afec\"\n\t            },\n\t            \"headline\": \"Python Functions: Definition, Scope, and Returns\",\n\t            \"datePublished\": \"2025-11-24T17:50:23+00:00\",\n\t            \"dateModified\": \"2025-11-24T17:51:06+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/\"\n\t            },\n\t            \"wordCount\": 696,\n\t            \"commentCount\": 0,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/09\\\/python-green-letters-cloud-programming-languages.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"Jupyter Notebook\",\n\t                \"PyCharm\",\n\t                \"Python\",\n\t                \"VSCode\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Python Development\",\n\t                \"Quant\",\n\t                \"Quant Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"CommentAction\",\n\t                    \"name\": \"Comment\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#respond\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/\",\n\t            \"name\": \"Python Functions: Definition, Scope, and Returns | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/09\\\/python-green-letters-cloud-programming-languages.jpg\",\n\t            \"datePublished\": \"2025-11-24T17:50:23+00:00\",\n\t            \"dateModified\": \"2025-11-24T17:51:06+00:00\",\n\t            \"description\": \"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/ibkr-quant-news\\\/python-functions-definition-scope-and-returns\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/09\\\/python-green-letters-cloud-programming-languages.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2023\\\/09\\\/python-green-letters-cloud-programming-languages.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Python\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/41e9bacc875edb13ed6288f4ffb2afec\",\n\t            \"name\": \"Jason\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/jasonpyquantnews\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Functions: Definition, Scope, and Returns","description":"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/235031\/","og_locale":"en_US","og_type":"article","og_title":"Python Functions: Definition, Scope, and Returns","og_description":"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/","og_site_name":"IBKR Campus US","article_published_time":"2025-11-24T17:50:23+00:00","article_modified_time":"2025-11-24T17:51:06+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","type":"image\/jpeg"}],"author":"Jason","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jason","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#article","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/"},"author":{"name":"Jason","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/41e9bacc875edb13ed6288f4ffb2afec"},"headline":"Python Functions: Definition, Scope, and Returns","datePublished":"2025-11-24T17:50:23+00:00","dateModified":"2025-11-24T17:51:06+00:00","mainEntityOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/"},"wordCount":696,"commentCount":0,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","keywords":["Data Science","Jupyter Notebook","PyCharm","Python","VSCode"],"articleSection":["Data Science","Programming Languages","Python Development","Quant","Quant Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/","url":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/","name":"Python Functions: Definition, Scope, and Returns | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#primaryimage"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","datePublished":"2025-11-24T17:50:23+00:00","dateModified":"2025-11-24T17:51:06+00:00","description":"Python, a versatile programming language, is fundamental in web development, data science, machine learning, and automation.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/ibkr-quant-news\/python-functions-definition-scope-and-returns\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","width":1000,"height":563,"caption":"Python"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/41e9bacc875edb13ed6288f4ffb2afec","name":"Jason","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/jasonpyquantnews\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/09\/python-green-letters-cloud-programming-languages.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/235031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/1518"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=235031"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/235031\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/196081"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=235031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=235031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=235031"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=235031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}