Fifteen functions that are always there, no import needed โ I/O, type conversion, math, number-base conversion, iterables, introspection, and documentation lookup.
This session covers Python's built-in functions โ functions that are always available without needing to import anything. These are fundamental utilities used constantly in everyday Python programming: I/O, type conversion, math operations, and introspection (inspecting objects/functions).
print, input), type conversion (int, type), math (abs, pow, round, divmod), number base conversion (bin, oct, hex), iterable operations (len, sum, min, max), character/code conversion (ord), object introspection (id), and documentation lookup (help).Prints output to the console (stdout by default).
print("Hello world")
Output:
Hello world
๐ Full signature (from help('print')):
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Optional keyword arguments:
| Argument | Meaning | Default |
|---|---|---|
file | A file-like stream to write to | sys.stdout |
sep | String inserted between multiple values | ' ' (space) |
end | String appended after the last value | '\n' (newline) |
flush | Whether to forcibly flush the stream | False |
๐ก Tip: Usesepandendto customize how multiple print statements or values are formatted, e.g.print("a", "b", sep="-")โa-b.
Reads a line of text typed by the user and returns it as a string.
input("Enter your name")
Interaction:
Enter your nameNitish
Output:
'Nitish'
Important Points
input() always returns a string, even if the user types a number โ you must manually convert it (e.g., using int()) if numeric use is needed.Returns the data type/class of an object.
a = True
type(a)
Output:
bool
๐ก Useful for debugging โ quickly check what kind of object a variable is.
int() converts a value (like a float or string) into an integer.
int(5.6)
# float
# str
# list
# tuple
Output:
5
Important Points
int(5.6) truncates the decimal part (does not round) โ result is 5, not 6.float(), str(), list(), tuple() โ these convert values into their respective types.# float, # str, # list, # tuple) appear to just be a note-to-self listing related conversion functions, not executable code.Returns the absolute value (removes the negative sign) of a number.
abs(-4)
Output:
4
Returns the value of a number raised to a power (like **, but as a function).
pow(2, 3)
Output:
8
pow(2, -3)
Output:
0.125
Important Points
pow(base, exponent) โ a negative exponent produces a fractional (float) result, since it's equivalent to 1 / (base ** abs(exponent)).pow() also supports an optional third argument for modular exponentiation: pow(base, exp, mod) (not shown in this screenshot, but part of Python's standard signature).Return the smallest or largest item in an iterable.
max([2, 1, 3, 0])
Output: 3
min([2, 1, 3, 0])
Output: 0
min("kolkata")
Output: 'a'
Important Points
min("kolkata") returns 'a' because 'a' has the lowest character value among the letters present.Rounds a number to the nearest value, optionally to a specified number of decimal places.
c = 22/7
round(c, 2)
Output: 3.14
round(c)
Output: 3
Important Points
round(number, ndigits) โ rounds to ndigits decimal places.round(number) (no second argument) โ rounds to the nearest whole integer.Returns a tuple containing the quotient and remainder of a division, in one call.
divmod(5, 2)
Output:
(2, 1)
๐ก Equivalent to (5 // 2, 5 % 2) but computed in a single, efficient call. Useful when you need both quotient and remainder together.
Convert an integer into its binary, octal, or hexadecimal string representation.
hex(4)
Output: '0x4'
oct(4)
Output: '0o4'
Important Points
hex() output is prefixed with 0x.oct() output is prefixed with 0o.bin() would return a string prefixed with 0b.Returns the unique memory identity (address) of an object โ an integer that is unique for the object's lifetime.
a = 3
id(a)
Output:
140721404847984
Important Points
id() while it exists in memory.id(a) == id(b)) rather than just equal values.Returns the Unicode/ASCII code point (integer) of a single character.
ord('A')
Output:
65
๐ก The reverse function is chr(), which converts a code point back into a character (not shown in screenshots, but a natural pairing to remember).
Returns the number of items in a sequence or collection (list, string, tuple, dict, etc.).
len([1, 2, 3])
Output:
3
Returns the sum of all items in an iterable, plus an optional starting value.
sum() # (being typed in the notebook โ incomplete example)
๐ Full signature (from help('sum')):
sum(iterable, /, start=0)
Behavior:
start value (default 0) plus all items of an iterable of numbers.start value.Example (inferred usage pattern):
sum([1, 2, 3]) # โ 6
sum([1, 2, 3], 10) # โ 16 (start=10)
Displays the documentation (docstring) for a function, module, or object โ extremely useful for quickly checking a function's signature and behavior without leaving the notebook.
help('print')
Output (partial):
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
help('sum')
Output (partial):
Help on built-in function sum in module builtins:
sum(iterable, /, start=0)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
๐ก Tip:help()can be called with either the function name as a string (help('print')) or the function object itself (help(print)) โ both work.
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
input("prompt") # always returns a string
type(obj) # returns the class/type of obj
int(x) # converts x to int (truncates floats)
abs(x) # absolute value
pow(base, exp) # exponentiation (like base ** exp)
min(iterable) # smallest item
max(iterable) # largest item
round(number, ndigits=None) # rounds; ndigits omitted โ nearest int
divmod(a, b) # returns (a // b, a % b) as a tuple
bin(x) # binary string, prefixed '0b'
oct(x) # octal string, prefixed '0o'
hex(x) # hex string, prefixed '0x'
id(obj) # unique memory identity of obj
ord(char) # Unicode code point of a single character
len(sequence) # number of items
sum(iterable, start=0) # sum of items + start value
help(obj_or_name) # shows documentation
input() always returns a string โ convert explicitly if you need a number.int() truncates, it does not round.round(x) with no second argument rounds to the nearest whole number; round(x, n) rounds to n decimal places.divmod(a, b) saves you from writing a // b and a % b separately.bin, oct, hex return strings, each with a distinctive prefix (0b, 0o, 0x).id() gives a memory address โ useful to check object identity, not equality.ord() and chr() are inverse operations (character โ code point).help() is a quick way to check any function's official docstring/signature directly in the notebook.Python has many built-in functions that require no imports:
print() outputs, input() reads a string from the user.type() shows an object's class; int(), float(), str(), list(), tuple() convert between types.abs() (absolute value), pow() (exponentiation), round() (rounding), divmod() (quotient + remainder together).bin(), oct(), hex() convert integers to binary/octal/hex strings.len() (count items), sum() (add items), min()/max() (smallest/largest).ord() converts a character to its Unicode code point.id() returns an object's unique memory identity.help() prints the docstring of any function โ great for quick reference while coding.