Skip to main content

Learning outcomes

By the end of this lecture, you should be able to:
  • identify built-in and user-defined functions
  • distinguish value-returning and non-value-returning functions
  • classify functions by role in beginner programs

Built-in functions

Python already provides many functions:
  • print()
  • len()
  • type()
  • sum()
  • min(), max()
  • sorted()
Example:
nums = [3, 1, 4]
print(len(nums))
print(max(nums))

User-defined functions

Functions written by programmer:
def square(x):
    return x * x

Value-returning functions

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

Non-value-returning functions

These mainly perform action:
def banner():
    print("Welcome")
Such functions still return None implicitly.

Functional role categories (beginner-friendly)

  • input helper functions
  • calculation functions
  • formatting or display functions
  • validation functions

Exam hints and traps

  • print() displays value, but usually returns None
  • sorted() returns new sorted list
  • list.sort() modifies list in place and returns None
  • built-in and user-defined functions can be used together

Quick practice

  1. Name three built-in functions.
  2. Write one user-defined function that doubles a number.
  3. Which is value-returning: print() or len()?

Answer key

  1. Sample: print, len, max
def double(x):
    return 2 * x
  1. len() is value-returning.