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()
User-defined functions
Functions written by programmer:Value-returning functions
These return data:Non-value-returning functions
These mainly perform action: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 returnsNonesorted()returns new sorted listlist.sort()modifies list in place and returnsNone- built-in and user-defined functions can be used together
Quick practice
- Name three built-in functions.
- Write one user-defined function that doubles a number.
- Which is value-returning:
print()orlen()?
Answer key
- Sample:
print,len,max
len()is value-returning.
