Skip to main content

Frequently Used Built-in Functions

This page keeps only the "frequently used and worth remembering" built-in functions. A common mistake is mixing them with string methods, list methods, and math module functions, so let's clarify the boundaries first:

  • Built-in functions: written directly as len(x), sorted(x), sum(x)
  • Object methods: written as text.split(), items.append(x)
  • Standard library functions: written as math.sqrt(x), json.loads(text)

Type Conversion

int("12")
float("3.14")
str(123)
list((1, 2, 3))
tuple([1, 2, 3])
set([1, 2, 2, 3])
dict([("a", 1), ("b", 2)])

Numeric and Statistical

abs(-10)
round(3.14159, 2)
pow(2, 5)
sum([1, 2, 3])
max([1, 2, 3])
min([1, 2, 3])
divmod(10, 3)

Iteration and Aggregation

len([1, 2, 3])
sorted([3, 1, 2])
reversed([1, 2, 3])
enumerate(["a", "b", "c"])
zip([1, 2], ["a", "b"])
any([False, False, True])
all([True, True, True])

Mapping and Filtering

list(map(str, [1, 2, 3]))
list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4]))

If the logic isn't complex, I more commonly use comprehensions rather than map() / filter().

Debugging and Representation

type("hello")
isinstance(3, int)
id("hello")
print("debug")
repr("hello")

Easily Confused Function Groups

sorted() vs list.sort()

numbers = [3, 1, 2]

new_numbers = sorted(numbers) # returns a new list
numbers.sort() # sorts in place

sum() and string concatenation

sum() is suitable for numbers, not for string concatenation. For string concatenation, prefer join().

map() doesn't return a list

In Python 3, map() returns an iterator. You typically need to wrap it with list(), or unpack it directly.

My most frequently used small set

If I had to pick just the ones I look back at most often, I'd choose:

  • len
  • sorted
  • sum
  • max
  • min
  • enumerate
  • zip
  • any
  • all
  • isinstance