Useful Python Built-in Functions and Methods List with Examples

By Digamber Rawat Last updated on
Today I am going to share with you a useful list of Python built-in functions and methods. Let’s understand what Python built-in functions are. Python built-in functions are those functions which are used to solve everyday programming tasks. These built-in functions are based on the functional programming model. We are going to discuss some of the best Python 3 built-in functions and methods in alphabetical order.

I will tell you about mostly used built-in methods in Python 3 along with the real-world examples. Now the question arises why do we need to check out this list, let me tell you why we need to have a look thoroughly in this useful Python 3 built-in functions list because these built-in functions will help us to solve common programming problems daily.

Built-in functions in Python

Python 3 offers nearly around 68 built-in functions and methods to make python developers life easy. You can see below mostly used Python built-in methods with examples.

Without further ado, Let’s begin checking out this useful Python 2 | 3 built-in methods cheat sheet.

If you are an absolute beginner in Python, then I would suggest you must check out Python’s official documentation here.

Python Built-in Functions Explained

Here is the Python built-in functions list.

abs( )
The abs() function in Python get the positive (absolute) value of a numerical value.

x = abs(-7.25)
print(x)

# output = 7.25
all()
The all() function in python checks if all the items of an iterable are true, else it returns False. The all() method also returns true if the iterable object is empty.

list = [0, 2, 2]
a = all(list)
print(a)

# output = False
any()
The any() function returns True if any item in an iterable is true, else it returns False. This method returns False if iterable is empty.

tuple = (0, 1, False)
a = any(tuple)
print(a)

# output = True
ascii()
The ascii() function returns a readable representation of an object (Strings, Tuples, Lists, etc.) It replaces non-ascii characters with escape characters.

a = ascii("Mostly Såne")
print(a)

# output = 'Mostly S\xe5ne'
bin()
The bin() function converts an integer (number) to a binary string. It prefixed with 0b.

a = bin(30)
print(a)

# output = 0b11110
bool()
The bool() function is very helpful in converting an object to a Boolean value. This function returns True, except the object is false, empty, 0 or none.

a = bool(22)
print(a)

# output = True
bytearray()
The bytearray() function is used converts an object into bytearray objects.

a = bytearray(22)
print(a)

# output = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
bytes()
The bytes() function is used to convert objects into bytes object.

a = bytes(22)
print(a)

# output: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
callable()
The callable() function gets True, and if the passed object is callable, else it returns false.

def a():
  b = 5

print(callable(a))

# output = True
chr()
The chr() function gets the string character, which represents the defined unicode.

a = chr(87)
print(a)

# output: W
compile()
The compile() function compiles the sources into a code.

a = compile('print(45)', 'test', 'eval')
exec(a)

# output: 45
complex()
The complex() function forms a complex number | convert string | number to complex number.

a = complex(2, 7)
print(a)

# output: (2+7j)
delattr()
The delattr() function help us to remove the defined attribute from the declared object.

class User:
  name = "Jaydon"
  mob = 182182922
  country = "Canada"

delattr(Person, 'age')
dict()
The dict() function form a new dictionary.

a = dict(name = "Jaydon", mob = 182182922, country = "Canada")
print(a)

# output = {'name': 'Jaydon', 'mob': 182182922, 'country': 'Canada'}
dir()
The dir() function gets all the properties and methods of the declared object, and It doesn’t get the values. It even returns the built-in properties which are default for all object.

class User:
  name = "Jaydon"
  mob = 182182922
  country = "Canada"

print(dir(User))

# output = ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'country', 'mob', 'name']
divmod()
Gets a tuple including the quotient and remainder when argument1 is divided by argument2.

a = divmod(6, 2)
print(a)

# output = (3, 0)
enumerate( )
It gets an enumerate object for a sequence or iterator.

a = ('john', 'ann', 'sia')
b = enumerate(a)
print(b)

# output = <enumerate object at 0x7f802a241a20>
eval()
Allows a legal python program to run python code.

a = 'print(28)'
print(eval(a))
exec()
The exec() function executes dynamic python code.

a = 'name = "John"\nprint(name)'
print(exec(a))
filter()
The filter() function filters the sequence via a function, this function checkes each elements in the iterator are true or not.

score = [15, 10, 20, 17, 26, 42]

def customFunc(a):
  if a < 20:
    return False
  else:
    return True

players = filter(customFunc, score)

for a in players:
  print(a)
float( )
The float() function transforms a numerical value to floating point.

a = float(5)

print(a)
format()
The format() function transforms the defined value into a specified format.

a = format(1.5, '%')

print(a)
frozenset()
The frozenset() function gets the unchangeable object.

list = ['Avengers', 'Wonder women', 'Batmen']
a = frozenset(list)

print(a)
getattr()
This function gets the value of the defined attribute from the particular object.

class Student:
  name = "Ann"
  age = 28
  country = "USA"

x = getattr(Student, 'age')

print(x)

# output = 28
globals( )
This function gets the dictionary from the current global symbol table.

a = globals()

print(a)
hasattr()
This function return True, if the defined object has the mentioned attribute, else it will return False.

class Student:
  name = "Ann"
  age = 28
  country = "USA"

x = hasattr(Student, 'age')

print(x)

# output = True
hex()
This method converts the numerical value into a hexadecimal value. The returned value comes with the 0x prefix.

a = hex(225)
print(a)

# output = 0xe1
id()
This method gets a unique id for the defined object, Python provides a unique id to all the objects.

a = ('oppo', 'iPhone', 'nokia')
b = id(a)

print(b)

# output = 140390324530704
input()
A user can define the value using the input() function.

print('What is your name:')
a = input()
print('Hi, ' + a)

# output = Enter your name:
# Digamber
# Hi, Digamber
int()
This function transforms the mentioned value into a numerical value.

a = int(2.9)
print(a)

# output = 2
issubclass()
Returns true, if the defined object is a subclass of the defined object, else it will return false.

class speed:
  kmph = 136

class car(speed):
  name = "BMW"
  speed = speed

x = issubclass(car, speed)

print(x)
iter()
This function gets an iterator object.

x = iter(["john", "lisa", "maria", "ava"])
print(next(x))
print(next(x))
print(next(x))
print(next(x))

# john
# lisa
# maria
# ava
len()
This method returns the total number of elements in an object if an object is a string type, then the method will return the number of characters from the string.

a = ["john", "lisa", "maria", "ava"]
print(len(a))

# 4
list()
The function generates a list object which is ordered and changeable.

a = list(["john", "lisa", "maria", "ava"])
print(len(a))

# 4

Digamber Rawat
Digamber Rawat

Full stack developer with a passion for UI/UX design. I create beautiful and useful digital products to solve people’s problem and make their life easy.

Thanks for checking this tutorial out :) Let me know if you have any suggestions or issue related to this tutorial, or you want to request a new tutorial. Just shoot me a mail here.