Python Built-in Functions

Built-in Functions



abs(x)


Returns the absolute value of x. abs(-5) # Output: 5

all(iterable)


Returns True if all elements in the iterable are true. all([True, False, True]) # Output: False

any(iterable)


Returns True if at least one element in the iterable is true. any([False, False, True]) # Output: True

bin(x)

Converts an integer to a binary string. bin(10) # Output: '0b1010'

bool(x)


Converts an object to a boolean value. bool(0) # Output: False

bytearray()


Return a new array of bytes. string = "Welcome" obj_byte_array = bytearray(string, "utf-8") print(obj_byte_array) # bytearray(b'Welcome')

bytes()


Return a new bytes object. data = "Welcome" obj_bytes = bytes(data, "utf-8") print(obj_bytes) # b'Welcome'

callable()


Return True if the object argument appears callable, False if not. def my_fun(): print("my function") a = "welcome" b = my_fun print(callable(a)) #False print(callable(b)) #True

chr()


Return the string representing a character whose Unicode code point is the integer. print(chr(98)) # 'b'

@classmethod


Transform a method into a class method. class MyClass: @classmethod def my_func(): print("class method")