René's URL Explorer Experiment


Title: Python Functions: def, Arguments, Return, Examples | TheCodeForge

Open Graph Title: Python Functions: def, Arguments, Return, Examples | TheCodeForge

Description: Python functions explained: def, arguments, defaults, *args and **kwargs, return values and scope — plus the mutable default argument trap.

Open Graph Description: Python functions explained: def, arguments, defaults, *args and **kwargs, return values and scope — plus the mutable default argument trap.

Opengraph URL: https://thecodeforge.io/python/functions-python/

direct link

Domain: thecodeforge.io


Hey, it has json ld scripts:
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://thecodeforge.io/python/functions-python/"
  },
  "headline": "Python Functions - Silent None Return Crashes",
  "description": "Python functions explained: def, arguments, defaults, *args and **kwargs, return values and scope — plus the mutable default argument trap.",
  "keywords": "Python Functions - Silent None Return Crashes, Python, Beginner, Functions, Python functions explained: def, arguments, defaults, *args and **kwargs, return values and scope — plus the mutable default argument trap.",
  "proficiencyLevel": "Beginner",
  "author": {
    "@type": "Person",
    "@id": "https://thecodeforge.io/about/#naren",
    "name": "Naren",
    "url": "https://thecodeforge.io/about/"
  },
  "publisher": {
    "@type": "Organization",
    "@id": "https://thecodeforge.io/#org",
    "name": "TheCodeForge",
    "url": "https://thecodeforge.io",
    "logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
  },
  "datePublished": "2026-03-05T00:00:00+00:00",
  "dateModified": "2026-09-23T00:00:00+00:00",
  "url": "https://thecodeforge.io/python/functions-python/",
  "inLanguage": "en",
  "educationalLevel": "Beginner",
  "image": "https://thecodeforge.io/assets/og-image.png",
  "isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
    {"@type": "ListItem", "position": 2, "name": "Python", "item": "https://thecodeforge.io/python/"},
    {"@type": "ListItem", "position": 3, "name": "Python Functions - Silent None Return Crashes", "item": "https://thecodeforge.io/python/functions-python/"}
  ]
}
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "What is a function in Python and why do we use it?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "A function is a named, reusable block of code that performs a specific task. We use functions to avoid repeating the same code in multiple places — the DRY principle — to break large problems into smaller, testable pieces, and to make code easier to maintain. You define it once with `def` and call it as many times as needed. If the logic changes, you update it in one place and every caller automatically gets the new behaviour."
      }
    },
    {
      "@type": "Question",
      "name": "What is the difference between return and print in a Python function?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "`print()` displays a value on screen and then it's gone — you can't store or reuse it. `return` sends the value back to whatever code called the function, where it can be stored in a variable, used in a calculation, or passed to the next function in a pipeline. If you ever find yourself storing the result of a function — `result = my_func()` — and getting None, the function is almost certainly using print instead of return. The fix is always to add the return statement."
      }
    },
    {
      "@type": "Question",
      "name": "Can a Python function return more than one value?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Yes — Python lets you return multiple values by separating them with commas: `return width, height`. Python automatically wraps them in a tuple, and on the calling side you can unpack them cleanly: `w, h = get_dimensions()`. This is idiomatic Python and appears constantly in professional codebases. You can also capture the whole tuple as a single variable and access elements by index if you prefer."
      }
    },
    {
      "@type": "Question",
      "name": "What happens if I forget to call a function — just write its name without parentheses?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Python won't raise an error — it will give you the function object itself rather than executing it and returning the result. This is a common beginner mistake: writing `result = my_function` instead of `result = my_function()`. The first stores a reference to the function; the second actually calls it and stores the return value. Always include parentheses when you intend to call a function. Type checkers like mypy can catch this mistake before it reaches production."
      }
    },
    {
      "@type": "Question",
      "name": "What is the LEGB rule in Python variable scope?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "LEGB stands for Local, Enclosing, Global, Built-in — the order Python searches for a variable name when it encounters one. First it checks Local (inside the current function), then Enclosing (outer functions, for nested functions), then Global (module level), then Built-in (Python's built-in names like print, len, range). Python stops at the first match. This explains why a local variable shadows a global one with the same name, why nested functions can access outer function variables without any special keyword, and why you can always call print() without importing it."
      }
    }
  ]
}

og:typewebsite
og:imagehttps://thecodeforge.io/assets/og-image.png
og:image:width1200
og:image:height630

Links:

TheCodeForge https://thecodeforge.io/
Pythonhttps://thecodeforge.io/python/
Buy me a coffee https://ko-fi.com/thecodeforge
1Functions in Pythonhttps://thecodeforge.io/python/functions-python/
2*args and **kwargs in Pythonhttps://thecodeforge.io/python/args-kwargs-python/
3Lambda Functions in Pythonhttps://thecodeforge.io/python/lambda-functions-python/
4Decorators in Pythonhttps://thecodeforge.io/python/decorators-python/
5Generators in Pythonhttps://thecodeforge.io/python/generators-python/
6Closures in Pythonhttps://thecodeforge.io/python/closures-python/
7Recursion in Pythonhttps://thecodeforge.io/python/recursion-python/
8map filter and reduce in Pythonhttps://thecodeforge.io/python/map-filter-reduce-python/
9Built-in Functions in Pythonhttps://thecodeforge.io/python/built-in-functions-python/
10Higher Order Functions in Pythonhttps://thecodeforge.io/python/higher-order-functions-python/
11functools Module in Pythonhttps://thecodeforge.io/python/functools-module-python/
← Back to Python track https://thecodeforge.io/python/
Homehttps://thecodeforge.io/
Pythonhttps://thecodeforge.io/python/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
 ● Production Incidenthttps://thecodeforge.io/python/functions-python/#v2-production-incident
 🔎 Debug Guidehttps://thecodeforge.io/python/functions-python/#v2-debug-guide
Pythonhttps://thecodeforge.io/python/introduction-python/
machinehttps://thecodeforge.io/ml-ai/introduction-machine-learning/
stringshttps://thecodeforge.io/python/strings-python/
closureshttps://thecodeforge.io/python/closures-python/
decoratorshttps://thecodeforge.io/python/decorators-python/
decoratorhttps://thecodeforge.io/java/decorator-pattern-java/
Type hintshttps://thecodeforge.io/python/type-hints-python/
→Python input() Returns Strings — TypeError Fixesinput() always returns a string, causing TypeError when adding integers. Learn why int() wrappers prevent silent failurehttps://thecodeforge.io/python/built-in-functions-python/
→TypeError: NoneType Is Not Subscriptable or IterableTypeError: 'NoneType' object is not subscriptable means you indexed None. Add the missing return, stop assigning sort()https://thecodeforge.io/python/python-typeerror-nonetype/
→Python Closures — Late Binding Loop Bug in Rate LimitersAll endpoints returned 429 after one hit its limit—closures captured loop variables by reference. Fix late binding and ihttps://thecodeforge.io/python/closures-python/
→Python Mutable Default Arguments — Data-Leak GotchaIntermittent personal data leaks? Python's mutable default args cause shared state at definition - avoid this gotcha thahttps://thecodeforge.io/interview/top-python-interview-questions/
→functools @lru_cache — Cross-User Cache LeakA @lru_cache on an instance method shared cache across users via identical self — debugging steps and per-instance cachehttps://thecodeforge.io/python/functools-module-python/
Build a Simple Image Classifier Without Writing Much Code (Teachable Machine + Export to Next.js)Beginnerhttps://thecodeforge.io/ml-ai/no-code-image-classifier-teachable-machine/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
←Previousdefaultdict and OrderedDicthttps://thecodeforge.io/python/defaultdict-ordereddict-python/
Next*args and **kwargs in Python→https://thecodeforge.io/python/args-kwargs-python/
LinkedIn https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
Facebook https://www.facebook.com/profile.php?id=61583020033815
YouTube https://www.youtube.com/channel/UCMar7CF2EmCF1I2tw1tNVuQ
Javahttps://thecodeforge.io/java/
Pythonhttps://thecodeforge.io/python/
C / C++https://thecodeforge.io/c-cpp/
JavaScripthttps://thecodeforge.io/javascript/
DSAhttps://thecodeforge.io/dsa/
Databasehttps://thecodeforge.io/database/
System Designhttps://thecodeforge.io/system-design/
DevOpshttps://thecodeforge.io/devops/
C# / .NEThttps://thecodeforge.io/csharp/
PHPhttps://thecodeforge.io/php/
ML / AIhttps://thecodeforge.io/ml-ai/
Interviewhttps://thecodeforge.io/interview/
CS Fundamentalshttps://thecodeforge.io/cs-fundamentals/
Rusthttps://thecodeforge.io/rust/
Toolshttps://thecodeforge.io/tools/
Cheatsheetshttps://thecodeforge.io/cheatsheets/
Mobilehttps://thecodeforge.io/mobile/
Data Analyticshttps://thecodeforge.io/data-analytics/
Securityhttps://thecodeforge.io/security/
Frontendhttps://thecodeforge.io/frontend/
Data Engineeringhttps://thecodeforge.io/data-engineering/
Testinghttps://thecodeforge.io/testing/
Cloudhttps://thecodeforge.io/cloud/
Observabilityhttps://thecodeforge.io/observability/
Web Platformhttps://thecodeforge.io/web-platform/
🧯 Errors Explainedhttps://thecodeforge.io/errors/
⚒ Blueprintshttps://thecodeforge.io/blueprints/
⌨ Practicehttps://thecodeforge.io/practice/
Interview Prephttps://thecodeforge.io/interview/
DSA Problemshttps://thecodeforge.io/dsa/
Developer Toolshttps://thecodeforge.io/tools/
Cheat Sheetshttps://thecodeforge.io/cheatsheets/
Abouthttps://thecodeforge.io/about/
Sitemaphttps://thecodeforge.io/sitemap.xml
Privacyhttps://thecodeforge.io/privacy.html

Viewport: width=device-width, initial-scale=1.0

Robots: max-image-preview:large


URLs of crawlers that visited me.