0% found this document useful (0 votes)
2 views

Python_BuiltIn_Functions_Alphabetical

This document provides an overview of Python built-in functions, detailing their purpose and providing examples for each function. Functions covered include abs(), all(), any(), bin(), bool(), and many others, illustrating their usage in Python programming. The document serves as a reference for understanding and utilizing these built-in functions effectively.

Uploaded by

arrowakashcoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python_BuiltIn_Functions_Alphabetical

This document provides an overview of Python built-in functions, detailing their purpose and providing examples for each function. Functions covered include abs(), all(), any(), bin(), bool(), and many others, illustrating their usage in Python programming. The document serves as a reference for understanding and utilizing these built-in functions effectively.

Uploaded by

arrowakashcoc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Python Built-in Functions Explained

abs()

Returns the absolute value of a number.

Example:

abs(-7) -> 7

all()

Returns True if all elements in an iterable are true.

Example:

all([True, True]) -> True

any()

Returns True if any element in an iterable is true.

Example:

any([False, True]) -> True

ascii()

Returns a readable version of an object, escaping non-ASCII characters.

Example:

ascii('ñ') -> "'\xf1'"

bin()

Returns the binary representation of an integer.

Example:

bin(10) -> '0b1010'

bool()

Converts a value to Boolean.

Example:

bool(0) -> False


Python Built-in Functions Explained

breakpoint()

Drops into the debugger at the call site.

Example:

breakpoint()

bytearray()

Returns a bytearray object.

Example:

bytearray([65, 66]) -> bytearray(b'AB')

bytes()

Returns a bytes object.

Example:

bytes(3) -> b'\x00\x00\x00'

callable()

Checks if the object appears callable.

Example:

callable(len) -> True

chr()

Returns a character from the Unicode code.

Example:

chr(65) -> 'A'

classmethod()

Returns a class method for the given function.

Used with @classmethod.


Python Built-in Functions Explained

compile()

Compiles source into a code object.

Example:

compile('2+2', '', 'eval')

complex()

Creates a complex number.

Example:

complex(1, 2) -> (1+2j)

delattr()

Deletes an attribute from an object.

Example:

delattr(obj, 'attr')

dict()

Creates a dictionary.

Example:

dict(a=1, b=2)

dir()

Returns a list of valid attributes for an object.

Example:

dir([])

divmod()

Returns quotient and remainder.

Example:

divmod(8, 3) -> (2, 2)


Python Built-in Functions Explained

enumerate()

Returns an enumerate object.

Example:

enumerate(['a','b'])

eval()

Evaluates a string as Python expression.

Example:

eval('2+2') -> 4

exec()

Executes dynamically created Python code.

Example:

exec('x=5')

filter()

Filters items in an iterable.

Example:

filter(lambda x: x>0, [-1, 0, 1])

float()

Converts to floating-point number.

Example:

float('3.14')

format()

Formats a string.

Example:

format(5, '02') -> '05'


Python Built-in Functions Explained

frozenset()

Returns an immutable frozenset.

Example:

frozenset([1, 2, 3])

getattr()

Returns value of named attribute.

Example:

getattr(obj, 'attr')

globals()

Returns the global namespace dictionary.

hasattr()

Checks if object has attribute.

Example:

hasattr(obj, 'attr')

hash()

Returns hash value of an object.

Example:

hash('abc')

help()

Invokes built-in help system.

Example:

help(str)

hex()
Python Built-in Functions Explained

Returns hexadecimal string of an integer.

Example:

hex(255) -> '0xff'

id()

Returns the unique ID of an object.

Example:

id(42)

input()

Takes input from user.

Example:

input('Enter: ')

int()

Converts value to integer.

Example:

int('5')

isinstance()

Checks instance type.

Example:

isinstance(5, int)

issubclass()

Checks if a class is subclass of another.

Example:

issubclass(bool, int)
Python Built-in Functions Explained

iter()

Returns an iterator.

Example:

iter([1, 2])

len()

Returns length.

Example:

len('abc') -> 3

list()

Creates a list.

Example:

list('abc') -> ['a', 'b', 'c']

locals()

Returns the local namespace dictionary.

map()

Applies a function to items.

Example:

map(str.upper, ['a', 'b'])

max()

Returns maximum value.

Example:

max([1, 3]) -> 3

memoryview()
Python Built-in Functions Explained

Returns memory view object.

min()

Returns minimum value.

Example:

min([1, 3]) -> 1

next()

Retrieves next item from iterator.

Example:

next(iter([1, 2]))

object()

Creates a new featureless object.

oct()

Returns octal string.

Example:

oct(8) -> '0o10'

open()

Opens a file.

Example:

open('file.txt', 'r')

ord()

Returns Unicode code from a character.

Example:

ord('A') -> 65
Python Built-in Functions Explained

pow()

Power function.

Example:

pow(2, 3) -> 8

print()

Prints to stdout.

Example:

print('Hello')

property()

Returns a property attribute.

range()

Returns a range object.

Example:

range(3) -> [0, 1, 2]

repr()

Returns string representation.

Example:

repr('abc') -> "'abc'"

reversed()

Returns reversed iterator.

Example:

reversed([1, 2, 3])

round()
Python Built-in Functions Explained

Rounds a number.

Example:

round(3.14159, 2) -> 3.14

set()

Creates a set.

Example:

set([1, 2, 2]) -> {1, 2}

setattr()

Sets an attribute on an object.

Example:

setattr(obj, 'attr', val)

slice()

Creates a slice object.

Example:

slice(1, 5)

sorted()

Returns sorted list.

Example:

sorted([3, 1, 2])

staticmethod()

Defines a static method.

str()

Converts to string.
Python Built-in Functions Explained

Example:

str(123) -> '123'

sum()

Returns sum of elements.

Example:

sum([1, 2, 3]) -> 6

super()

Refers to parent class.

Example:

super().method()

tuple()

Creates a tuple.

Example:

tuple([1, 2])

type()

Returns the type of an object.

Example:

type(3) -> <class 'int'>

vars()

Returns __dict__ of an object.

zip()

Combines iterables.

Example:
Python Built-in Functions Explained

zip([1, 2], ['a', 'b'])

__import__()

Imports a module by name.

Example:

__import__('math')

You might also like