InfoparkDailyCAREER TOOLS

Python · Lesson 7 of 9

Functions

def, parameters, default values, return and keyword arguments.

A function packages code you want to reuse. Define it with def, give it parameters, and send a result back with return.

  • Default values: def greet(name="friend").
  • Keyword arguments: call as salary(lpa=6, months=12) — clearer and order-independent.
  • A function without return returns None.
  • Write a short docstring (the first string inside) to explain what the function does.

Try it yourself

Press Run to see the output.

Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.

Key points

  • def name(params): then an indented body.
  • return sends a value back.
  • Defaults and keyword arguments make calls readable.

Quick check

What does a function return if it has no return statement?

Practice task

Write is_eligible(age, degree) that returns True when age is 18–30 and degree is "BTech" or "MCA". Test it with three calls.

Interview corner

What are *args and **kwargs?

*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They let a function accept a flexible number of inputs.

Why shouldn't you use a list as a default argument value?

Defaults are evaluated once, when the function is defined, so the same list is shared between calls and changes leak across calls. Use None and create the list inside.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.