HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to Python: Print and RepeatVariablesData Types & NumbersStringsListsConditions (if / elif / else)Loops (for / while)FunctionsOperatorsDictionariesTuples & SetsError Handling (try / except)Classes (Object-Oriented)File OperationsComments & IndentationBooleans (True / False)Lambda & map / filterModules (import)InheritanceVariable Scope
REFERENCE
📖 Overview
🖥️ Output & Input
🔢 Numbers & Math
✍️ String
📋 List
🗂️ Dictionary & Set
🔁 Condition & Loop
🧩 Function
def / returndefault parameter*args / **kwargslambda
📁 File & Error
🔄 Type & Conversion
Python›REFERENCE›Function›def / return

def / return

Defines your own function (command).

Syntax

def name(param):
    return value

Description

Binds a repeated task to a name. It takes data via parameters and returns a result with return. If there's no return, it returns None.

Parameters

parameter(optional)The input(s) given to the function.

Returns

The value specified with return.

Example

Loading editor…

Expected output

25

When to use?

Avoiding code repetition, breaking the program into readable pieces.

Common mistakes

  • ⚠️ If you don't write return, the function returns None; print and return are different.

Related commands

default parameterlambda
default parameter →
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code