Fundamentals 14 min read

Python Built-in Functions: Comprehensive Guide and Examples

This article presents a comprehensive overview of Python's 68 built-in functions up to version 3.6.2, categorizing them into twelve groups such as numeric operations, data structures, scope, iterators, I/O, memory, file handling, modules, and more, with clear code examples.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Built-in Functions: Comprehensive Guide and Examples

Python Built-in Functions Overview

Python provides a set of built‑in functions that can be used directly, such as print, input, etc. Up to version 3.6.2 there are 68 built‑in functions.

Numeric‑related Functions

Data types: bool, int, float, complex Base conversion: bin(), oct(), hex() Math operations: abs(), divmod(), round(), pow(), sum(), min(),

max()
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
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

Data‑Structure‑related Functions

Sequences: list(), tuple() Collections: dict(), set(), frozenset() Utility: reversed(), slice(), len(), sorted(), enumerate(), zip(), filter(),

map()
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 = [1,2,3,4,5,6,7,8,9]
print(sorted(lst, reverse=True))  # [9,8,7,6,5,4,3,2,1]
for index, item in enumerate(['one','two','three'], 1):
    print(index, item)

Scope‑related Functions

locals()

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

def func():
    a = 10
    print(locals())
    print(globals())
    print("Example")
func()

Iterator and Generator Functions

range()

, iter(),

next()
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

String Execution Functions

eval()

, exec(),

compile()
s = input("Enter expression a+b:")
print(eval(s))   # evaluates the expression
code = "for i in range(3): print(i)"
exec(code)

Input/Output Functions

print()

– prints to console. input() – reads user input.

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

Memory‑related Functions

hash()

– returns hash value of an object. id() – returns the memory address.

s = "alex"
print(hash(s))
print(id(s))

File Operations

open()

– opens a file and returns a file object.

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

Module‑related Functions

__import__()

– imports a module dynamically.

name = input("Enter module name:")
module = __import__(name)

Help and Introspection

help()

– shows documentation of an object. callable() – checks if an object can be called. dir() – lists attributes of an object.

print(help(str))
print(callable(len))
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 Structuresprogramming basics
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

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.