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

Built-In Functions and Methods

Uploaded by

Bandari Ganesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Built-In Functions and Methods

Uploaded by

Bandari Ganesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

In Python, there are many built-in functions and methods available for various operations.

Here's a list
of the most common built-in functions and methods:

Built-in Functions:
1. Type Conversion Functions:
int() : Converts a value to an integer.

float() : Converts a value to a floating-point number.

str() : Converts a value to a string.

bool() : Converts a value to a boolean (True or False).

complex() : Converts a value to a complex number.

list() : Converts a value to a list.

tuple() : Converts a value to a tuple.

set() : Converts a value to a set.

dict() : Converts a value to a dictionary.

2. Mathematical Functions:
abs() : Returns the absolute value of a number.

pow() : Returns the value of x raised to the power y (x^y).

round() : Rounds a number to a given precision.

sum() : Sums an iterable (e.g., a list or tuple).

min() : Returns the smallest item from an iterable.

max() : Returns the largest item from an iterable.

divmod() : Returns the quotient and remainder as a tuple.

3. Input/Output Functions:
print() : Outputs data to the console.

input() : Gets user input as a string.

open() : Opens a file and returns a file object.

4. Utility Functions:
len() : Returns the length of an object (e.g., list, string).

type() : Returns the type of an object.

isinstance() : Checks if an object is an instance of a class or type.

id() : Returns the unique identifier for an object.

dir() : Returns a list of attributes and methods of an object.

help() : Displays the documentation of an object or function.

range() : Generates a sequence of numbers.

5. Iterators and Generators:


enumerate() : Returns an enumerate object, pairing each element with its index.

map() : Applies a function to every item in an iterable.

filter() : Filters an iterable using a function.

zip() : Combines elements from multiple iterables.

6. Object-related Functions:
callable() : Checks if an object is callable.

getattr() : Returns the value of an attribute from an object.

setattr() : Sets an attribute's value.

delattr() : Deletes an attribute from an object.


hasattr() : Checks if an object has a certain attribute.

7. Sorting and Reversing:


sorted() : Returns a sorted list from the items of an iterable.

reversed() : Returns a reverse iterator of a sequence.

8. Memory Management:
id() : Returns the memory address of an object.

globals() : Returns a dictionary of the current global symbol table.

locals() : Returns a dictionary of the current local symbol table.

9. Exception Handling Functions:


try , except , finally : Control flow for handling exceptions.

raise : Used to raise an exception manually.

10. Other Built-in Functions:

all() : Returns True if all elements in an iterable are true.

any() : Returns True if any element in an iterable is true.

bin() : Converts an integer to binary.

oct() : Converts an integer to octal.

hex() : Converts an integer to hexadecimal.

eval() : Evaluates a Python expression.

exec() : Executes Python code dynamically.

compile() : Compiles a source into a code object.

Commonly Used Methods:


Methods are typically bound to specific data types (e.g., strings, lists, dictionaries):
1. String Methods:
upper() : Converts a string to uppercase.

lower() : Converts a string to lowercase.

replace() : Replaces substrings.

find() : Returns the index of the first occurrence of a substring.

split() : Splits a string into a list.

join() : Joins a list of strings into one string.

2. List Methods:
append() : Adds an element to the end of a list.

extend() : Extends a list by appending elements from an iterable.

insert() : Inserts an element at a specific position.

remove() : Removes the first occurrence of a value.

pop() : Removes and returns the last or specified item in a list.

sort() : Sorts the list in place.

reverse() : Reverses the list in place.

3. Dictionary Methods:
keys() : Returns a view object of dictionary keys.

values() : Returns a view object of dictionary values.


items() : Returns a view object of dictionary key-value pairs.

get() : Returns the value of a key.

update() : Updates the dictionary with elements from another dictionary or iterable.

4. Set Methods:
add() : Adds an element to a set.

remove() : Removes an element from a set.

union() : Returns the union of sets.

intersection() : Returns the intersection of sets.

difference() : Returns the difference of sets.

These are just some of the core functions and methods in Python. There's a vast array of modules and
libraries that offer even more specialized functions.

You might also like