Fundamentals 11 min read

Common Python Built‑in Functions: 68 Frequently Used Examples

This article introduces 68 commonly used Python built‑in functions across numeric, string, list, dictionary, tuple, set, file‑handling, and other categories, providing concise explanations and code examples that help programmers efficiently manipulate core data types and improve coding productivity.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Common Python Built‑in Functions: 68 Frequently Used Examples

Python is a popular programming language with a powerful standard library; this article presents 68 frequently used built‑in functions, grouped by data type, and supplies clear code examples for each.

Numeric functions such as abs(), divmod(), pow() and round() demonstrate how to obtain absolute values, quotient‑remainder pairs, exponentiation, and rounding:

a = -5
print(abs(a))  # 5

a, b = 10, 3
print(divmod(a, b))  # (3, 1)

print(pow(2, 3))  # 8

a = 2.8
print(round(a))  # 3

String functions include chr(), ord(), len(), str(), capitalize(), lower(), upper(), swapcase(), title(), strip(), replace(), split() and join(), illustrating character conversion, length retrieval, case manipulation, whitespace trimming, substitution, splitting, and joining operations.

print(chr(97))          # 'a'
print(ord('a'))        # 97
s = 'hello world'
print(len(s))          # 11
print(str(123))        # '123'
print(s.capitalize())   # 'Hello world'
print(s.upper())        # 'HELLO WORLD'
print(s.swapcase())    # 'hELLO wORLD'
print(s.title())       # 'Hello World'
print(s.strip())       # 'hello world'
print(s.replace('l','i')) # 'heiioworid'
print('hello,world'.split(',')) # ['hello', 'world']
print('-'.join(['hello','world'])) # 'hello-world'

List functions such as len(), max(), min(), sum(), sorted(), reversed(), list(), append(), insert(), remove(), pop(), extend(), index(), and count() show how to query size, find extrema, aggregate, reorder, convert, and modify list contents.

lst = [1, 2, 3, 4, 5]
print(len(lst))   # 5
print(max(lst))   # 5
print(min(lst))   # 1
print(sum(lst))    # 15
print(sorted([3,1,4,2,5])) # [1, 2, 3, 4, 5]
print(list(reversed(lst))) # [5, 4, 3, 2, 1]
lst.append(6)
print(lst)        # [1,2,3,4,5,6]
lst.insert(1, 0)
print(lst)        # [1,0,2,3,4,5,6]
lst.remove(3)
print(lst)        # [1,0,2,4,5,6]
print(lst.pop())  # 6

Dictionary functions like len(), keys(), values(), items(), get(), pop(), and update() illustrate how to inspect size, retrieve keys/values, safely access entries, delete items, and merge mappings.

d = {'a':1, 'b':2, 'c':3}
print(len(d))          # 3
print(d.keys())        # dict_keys(['a','b','c'])
print(d.values())      # dict_values([1,2,3])
print(d.items())       # dict_items([('a',1),('b',2),('c',3)])
print(d.get('a'))      # 1
print(d.get('d',0))    # 0
print(d.pop('b'))      # 2
print(d)                # {'a':1,'c':3}
d1 = {'a':1,'b':2}
d2 = {'b':3,'c':4}
d1.update(d2)
print(d1)               # {'a':1,'b':3,'c':4}

Tuple functions ( len(), max(), min(), tuple()) demonstrate length, extremum retrieval, and conversion from other iterables.

t = (1,2,3)
print(len(t))   # 3
print(max(t))   # 3
print(min(t))   # 1
print(tuple([4,5,6])) # (4,5,6)

Set functions ( len(), max(), min(), set(), add(), remove()) cover size, extremum, creation, addition, and removal of elements.

s = {1,2,3}
print(len(s))   # 3
print(max(s))   # 3
print(min(s))   # 1
print(set([4,5])) # {4,5}
s.add(4)
print(s)        # {1,2,3,4}
s.remove(2)
print(s)        # {1,3,4}

File‑handling functions ( open(), close(), read(), write()) show basic file I/O operations.

f = open('test.txt','r')
content = f.read()
print(content)
f.close()

f = open('test.txt','w')
f.write('hello world
')
f.close()

Other useful functions such as isinstance(), range(), zip(), map(), filter(), reduce(), and another round() example illustrate type checking, sequence generation, aggregation, and functional programming utilities.

print(isinstance(10,int))   # True
print(list(range(5)))       # [0,1,2,3,4]
print(list(zip([1,2,3],['a','b','c']))) # [(1,'a'),(2,'b'),(3,'c')]
print(list(map(lambda x: x*2, [1,2,3]))) # [2,4,6]
print(list(filter(lambda x: x%2==0, [1,2,3,4,5]))) # [2,4]
from functools import reduce
print(reduce(lambda x,y: x*y, [1,2,3])) # 6
print(round(2.8)) # 3

In summary, these 68 built‑in functions provide convenient operations for common data types, helping developers write clearer and more efficient Python code.

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.

programmingdata-structuresbuilt-in-functions
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

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.