Published by Patrick Mutisya · 14 days ago
Built‑in functions are part of the core language. They are always available without importing any module. They perform common tasks such as I/O, type conversion, and sequence handling.
print() – output to the console.input() – read a line of text from the user.len() – return the length of a sequence.range() – generate an immutable sequence of numbers.type() – return the data type of an object.int(), float(), str() – type conversion functions.Library routines are functions that reside in modules (libraries). To use them you must import the relevant module. They extend the language with specialised capabilities such as mathematics, random number generation, file handling, and system interaction.
math ModuleThe math module provides functions such as sqrt(), sin(), and constants like pi. To use them you must import the module first.
import mathradius = 5
area = math.pi * math.pow(radius, 2) # \$A = \pi r^2\$
print("Area =", area)
random ModuleGenerating a random integer between 1 and 10:
import randomvalue = random.randint(1, 10)
print("Random value:", value)
| Aspect | Built‑in Function | Library Routine |
|---|---|---|
| Availability | Always available | Requires import |
| Typical Use | Basic I/O, type conversion, simple sequence operations | Specialised tasks – maths, random numbers, file system, networking |
| Namespace | Global namespace | Accessed via module.function or from module import … |
| Performance | Generally faster (no import overhead) | May be slightly slower due to module lookup |
import * to keep the namespace clear.from math import sqrt, pi when only a few functions are required.random.seed()).sum() (built‑in) and len() (built‑in).math.pow(x, y) and the exponentiation operator x**y.random module and justify your choice.