Fundamentals 17 min read

Unlock Python’s 68 Built‑in Functions: A Complete Guide for Beginners

This article presents all 68 built‑in functions available in Python 3.6.2, categorizes them into twelve groups, and provides clear code examples for each function, helping beginners quickly master essential Python utilities for data types, conversions, mathematics, collections, scope, iteration, and more.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Unlock Python’s 68 Built‑in Functions: A Complete Guide for Beginners

Built‑in functions are ready‑to‑use utilities provided by Python, such as print and input. As of Python 3.6.2 there are 68 built‑in functions, listed below and organized into twelve thematic groups.

abs()           dict()          help()          min()           setattr()
all()           dir()           hex()           next()          slice()
any()           divmod()        id()            object()        sorted()
ascii()        enumerate()     input()         oct()           staticmethod()
bin()          eval()          int()           open()          str()
bool()         exec()          isinstance()    ord()           sum()
bytearray()    filter()        issubclass()    pow()           super()
bytes()        float()         iter()          print()         tuple()
callable()     format()        len()           property()      type()
chr()          frozenset()    list()          range()         vars()
classmethod() getattr()       locals()        repr()          zip()
compile()      globals()       map()           reversed()      __import__()
complex()      hasattr()       max()           round()
delattr()     hash()          memoryview()    set()

Related to Numbers

1. Data Types

bool: Boolean ( True, False)

int: Integer

float: Floating‑point number

complex: Complex number

2. Base Conversion

bin()

– convert to binary oct() – convert to octal hex() – convert to hexadecimal

print(bin(10))   # binary: 0b1010
print(hex(10))   # hexadecimal: 0xa
print(oct(10))   # octal: 0o12

3. Mathematical Operations

abs()

– absolute value divmod() – quotient and remainder round() – round to nearest pow(a, b) – a to the power of b (optional third argument for modulo) sum() – sum of an iterable min() – smallest value max() – largest value

print(abs(-2))                     # 2
print(divmod(20, 3))               # (6, 2)
print(round(4.50))                 # 4
print(round(4.51))                 # 5
print(pow(10, 2, 3))               # 1 (10**2 % 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

Related to Data Structures

1. Sequences

(1) Lists and tuples list() – convert an iterable to a list tuple() – convert an iterable to a tuple

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)

(2) Related built‑ins reversed() – return an iterator that yields items in reverse order slice() – create a slice object for list slicing

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]

(3) Strings str() – convert to string

print(str(123) + '456')   # 123456

Formatting examples

s = "hello world!"
print(format(s, "^20"))   # centered
print(format(s, "<20"))   # left‑aligned
print(format(s, ">20"))   # right‑aligned
print(format(3, 'b'))      # binary: 11
print(format(97, 'c'))     # unicode character: a
print(format(11, 'd'))     # decimal: 11
print(format(11, 'o'))     # octal: 13
print(format(11, 'x'))     # hex (lower): b
print(format(11, 'X'))     # hex (upper): B
print(format(11, 'n'))     # same as decimal: 11
print(format(123456789, 'e'))   # scientific notation
print(format(123456789, '0.2e'))# 1.23e+08
print(format(1.23456789, 'f'))   # 1.234569
print(format(1.23456789, '0.2f'))# 1.23

2. Collections

dict()

– create a dictionary set() – create a set frozenset() creates an immutable set.

3. Related built‑ins

len()

– number of items sorted() – return a sorted list (optional key and reverse)

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))   # [1, 5, 5, 6, 7, 9, 12, 13, 18]
print(sorted(lst, reverse=True)) # [18, 13, 12, 9, 7, 6, 5, 5, 1]

words = ['one','two','three','four','five','six']
def f(s):
    return len(s)
print(sorted(words, key=f)) # ['one', 'two', 'six', 'four', 'five', 'three']
enumerate()

– get index‑value pairs from an iterable

lst = ['one','two','three','four','five']
for index, el in enumerate(lst, 1):
    print(index)
    print(el)
all()

– True if every element is truthy any() – True if any element is truthy

print(all([1, 'hello', True, 9]))   # True
print(any([0,0,0,False,1,'good'])) # True
zip()

– aggregate elements from multiple iterables into tuples

lst1 = [1,2,3,4,5,6]
lst2 = ['醉乡民谣','驴得水','放牛班的春天','美丽人生','辩护人','被嫌弃的松子的一生']
lst3 = ['美国','中国','法国','意大利','韩国','日本']
for el in zip(lst1, lst2, lst3):
    print(el)
filter()

– filter items using a predicate function

def func(i):
    return i % 2 == 1
lst = [1,2,3,4,5,6,7,8,9]
print(list(filter(func, lst)))   # [1, 3, 5, 7, 9]
map()

– apply a function to each item of an iterable

def f(i):
    return i
lst = [1,2,3,4,5,6,7]
print(list(map(f, lst)))   # [1, 2, 3, 4, 5, 6, 7]

Related to Scope

locals()

– dictionary of the current local symbol table globals() – dictionary of the global symbol table

def func():
    a = 10
    print(locals())   # {'a': 10}
    print(globals())  # global symbols
    print("今天内容很多")
func()

Related to Iterators and Generators

range()

– generate a sequence of numbers next() – retrieve the next item from an iterator iter() – obtain an iterator from an iterable

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

Executing String‑Type Code

eval()

– evaluate an expression string and return the result exec() – execute a block of code (no return value) compile() – compile source code into a code object for later execution or evaluation

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
code1 = "for i in range(3): print(i)"
com = compile(code1, "", mode="exec")
exec(com)                     # 0 1 2
code2 = "5+6+7"
print(eval(compile(code2, "", mode="eval")))  # 18

Input and Output

print()

– display output input() – read user input

print("hello", "world", sep="*", end="@")   # hello*world@

Memory Related

hash()

– compute hash value of an object (used by dict) id() – obtain the memory address of an object

s = "alex"
print(hash(s))   # example hash value
print(id(s))     # memory address

File Operations

open()

– open a file and return a file object

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

Modules

__import__()

– import a module programmatically

import os
name = input("请输入你要导入的模块:")
__import__(name)

Help

help()

– display the documentation of an object

print(help(str))

Calling

callable()

– check if an object appears callable

a = 10
print(callable(a))   # False

def f():
    print("hello")
print(callable(f))    # True

Inspect Built‑in Attributes

dir()

– list the attributes of an object

print(dir(tuple))
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonData TypesCode Examplesprogramming fundamentalsbuilt-in functions
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

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.