Fundamentals 14 min read

Comprehensive Guide to Python Built‑in Functions (68 Functions)

This article lists and explains all 68 built‑in functions provided by Python 3.6.2, grouping them into twelve thematic categories and illustrating each with clear code examples covering numeric conversion, data structures, scope, iteration, I/O, memory, file handling, modules, and utility helpers.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Comprehensive Guide to Python Built‑in Functions (68 Functions)

Python provides 68 built‑in functions (as of version 3.6.2) such as print , input , abs , len , etc., which can be used directly without importing modules.

The functions are grouped into twelve thematic groups: numeric‑related (data types, base conversion, arithmetic), data‑structure‑related (sequences, collections, related utilities), scope‑related, iterator‑generator‑related, string execution, input‑output, memory‑related, file‑operation, module‑related, help, callable, and attribute‑inspection.

Numeric‑related examples show base conversion and arithmetic:

<code>print(bin(10))   # 二进制:0b1010
print(hex(10))   # 十六进制:0xa
print(oct(10))   # 八进制:0o12
print(abs(-2))   # 绝对值:2
print(divmod(20,3))  # (6, 2)
print(round(4.51))   # 5
print(pow(10,2,3))   # 1 (10² mod 3)
print(sum([1,2,3,4,5,6,7,8,9,10]))   # 55
print(min(5,3,9,12,7,2))   # 2
print(max(7,3,15,9,4,13))   # 15</code>

Data‑structure examples demonstrate converting iterables, reversing, slicing, and string conversion:

<code>print(list((1,2,3,4,5,6)))   # [1, 2, 3, 4, 5, 6]
print(tuple([1,2,3,4,5,6]))   # (1, 2, 3, 4, 5, 6)
lst = "你好啊"
it = reversed(lst)
print(list(it))   # ['啊', '好', '你']
lst = [1,2,3,4,5,6,7]
print(lst[1:3:1])   # [2, 3]
s = slice(1,3,1)
print(lst[s])   # [2, 3]
print(str(123) + '456')   # 123456
print(format('hello world!', '^20'))   # centered
print(format('hello world!', '<20'))   # left‑aligned
print(format('hello world!', '>20'))   # right‑aligned</code>

Utility functions such as len , sorted , enumerate , all , any , zip , filter , and map are described with usage examples:

<code>lst = [5,7,6,12,1,13,9,18,5]
lst.sort()
print(lst)   # [1, 5, 5, 6, 7, 9, 12, 13, 18]
print(sorted(lst, reverse=True))   # [18, 13, 12, 9, 7, 6, 5, 5, 1]
print(sorted(['one','two','three','four','five','six'], key=len))   # ['one','two','six','four','five','three']
for index, el in enumerate(['one','two','three','four','five'], 1):
    print(index, el)
print(all([1,'hello',True,9]))   # True
print(any([0,0,0,False,1,'good']))   # True
for el in zip([1,2,3,4,5,6], ['a','b','c','d','e','f'], ['X','Y','Z','W','U','V']):
    print(el)
print(list(filter(lambda i: i%2==1, [1,2,3,4,5,6,7,8,9])))   # [1,3,5,7,9]
print(list(map(lambda i: i, [1,2,3,4,5,6,7])))   # [1,2,3,4,5,6,7]</code>

Scope inspection uses locals() and globals() :

<code>def func():
    a = 10
    print(locals())   # {'a': 10}
    print(globals())   # {...}
    print("今天内容很多")
func()</code>

Iterator generation uses range() , iter() , and next() :

<code>for i in range(15, -1, -5):
    print(i)   # 15 10 5 0
lst = [1,2,3,4,5]
it = iter(lst)
print(next(it))   # 1
print(next(it))   # 2</code>

String execution functions eval , exec , and compile are shown:

<code>s1 = input("请输入a+b:")   # e.g., 8+9
print(eval(s1))   # 17
s2 = "for i in range(5): print(i)"
exec(s2)   # prints 0‑4
code = "5+6+7"
print(eval(compile(code, "", mode="eval")))   # 18</code>

Input‑output functions print() and input() are covered:

<code>print("hello", "world", sep="*", end="@")   # hello*world@</code>

Memory‑related helpers hash() and id() demonstrate obtaining hash values and object addresses:

<code>s = 'alex'
print(hash(s))   # e.g., -168324845050430382
print(id(s))   # e.g., 2278345368944</code>

File handling uses open() :

<code>f = open('file', mode='r', encoding='utf-8')
content = f.read()
f.close()</code>

Dynamic module loading uses __import__() :

<code>name = input("请输入你要导入的模块:")
__import__(name)</code>

Help utilities help() , callability check callable() , and attribute inspection dir() are demonstrated:

<code>print(help(str))
print(callable(10))   # False
print(callable(lambda x: x))   # True
print(dir(tuple))   # list of tuple methods</code>
data typesTutorialmemoryiterationbuilt-in-functionsfile-ioconversion
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.