DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

PYTHON: Functions

Learn Functions in PYTHON with practical examples.

Read time: 1 min Words: 37
Open Playground → PYTHON My Progress

PYTHON — Functions

Overview

Functions group reusable code and accept parameters.

What you'll learn

  • def
  • parameters
  • return
  • default values

Syntax

def add(a,b): return a+b

Example

def greet(name="Guest"):
    return f"Hello {name}"

print(greet("Ali"))
print(greet())

Notes

  • Keep functions small.
  • Return values instead of printing when possible.

    Try: Open the Playground: /en/playground/python