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

List of Python Functions

--

Uploaded by

shreya.y2612
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

List of Python Functions

--

Uploaded by

shreya.y2612
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

📌 Comprehensive List of Python Functions

Here’s a detailed list of all possible Python built-in functions that can be used on strings, arrays, lists,
trees, graphs, and other data structures, along with one-line descriptions.

📝 1. String Functions

Function Description

s.lower() Converts all characters to lowercase.

s.upper() Converts all characters to uppercase.

s.title() Converts the first letter of each word to uppercase.

s.capitalize() Capitalizes the first letter of the string.

s.strip() Removes leading and trailing spaces.

s.lstrip() Removes leading spaces.

s.rstrip() Removes trailing spaces.

s.replace(old, new) Replaces occurrences of a substring.

s.split(delimiter) Splits a string into a list.

s.join(iterable) Joins elements of an iterable into a string.

s.find(substring) Returns the index of the first occurrence, or -1 if not found.

s.index(substring) Returns the index of the first occurrence, raises an error if not found.

s.count(substring) Counts occurrences of a substring.

s.startswith(prefix) Checks if a string starts with a given prefix.

s.endswith(suffix) Checks if a string ends with a given suffix.

s.isdigit() Checks if the string consists of digits only.

s.isalpha() Checks if the string consists of letters only.

s.isalnum() Checks if the string consists of letters and numbers.

s.swapcase() Swaps lowercase to uppercase and vice versa.

sorted(s) Returns a sorted list of characters from the string.

reversed(s) Returns a reversed iterator of the string.


Function Description

Counter(s) Counts occurrences of each character in the string (from collections).

all(s) Returns True if all characters in the string are non-empty.

any(s) Returns True if at least one character is non-empty.

📌 2. List Functions

Function Description

len(lst) Returns the length of the list.

lst.append(item) Adds an item to the end of the list.

lst.extend(iterable) Extends the list with another iterable.

lst.insert(index, item) Inserts an item at a specific index.

lst.remove(item) Removes the first occurrence of an item.

lst.pop(index) Removes and returns an item at a given index.

lst.clear() Removes all elements from the list.

lst.index(item) Returns the index of the first occurrence.

lst.count(item) Counts occurrences of an item.

lst.sort() Sorts the list in ascending order.

lst.reverse() Reverses the list.

lst.copy() Returns a shallow copy of the list.

sorted(lst) Returns a sorted copy of the list.

sum(lst) Returns the sum of list elements.

max(lst) Returns the maximum element.

min(lst) Returns the minimum element.

reversed(lst) Returns a reversed iterator of the list.

all(lst) Returns True if all elements are truthy.

any(lst) Returns True if at least one element is truthy.

Counter(lst) Returns the count of each unique element (from collections).


📌 3. Tuple Functions

Function Description

len(tup) Returns the length of the tuple.

tup.count(item) Counts occurrences of an item.

tup.index(item) Returns the index of the first occurrence.

sorted(tup) Returns a sorted list of elements.

reversed(tup) Returns a reversed iterator of the tuple.

📌 4. Dictionary Functions

Function Description

dict.keys() Returns all keys in the dictionary.

dict.values() Returns all values in the dictionary.

dict.items() Returns key-value pairs as tuples.

dict.get(key, default) Returns value for a key, or default if not found.

dict.pop(key) Removes and returns a value for a key.

dict.update(dict2) Merges another dictionary.

dict.clear() Removes all key-value pairs.

dict.copy() Returns a shallow copy of the dictionary.

Counter(dict) Counts occurrences of dictionary values (from collections).

📌 5. Set Functions

Function Description

set.add(item) Adds an item to the set.

set.remove(item) Removes an item (raises an error if not found).

set.discard(item) Removes an item if it exists.

set.pop() Removes and returns a random element.


Function Description

set.clear() Removes all elements from the set.

set.union(set2) Returns the union of two sets.

set.intersection(set2) Returns the intersection of two sets.

set.difference(set2) Returns the difference between two sets.

set.issubset(set2) Checks if the set is a subset of another.

set.issuperset(set2) Checks if the set is a superset of another.

📌 6. Heap Functions (heapq module)

Function Description

heapq.heappush(heap, item) Adds an element to the heap.

heapq.heappop(heap) Removes and returns the smallest element.

heapq.heapify(lst) Converts a list into a heap.

📌 7. Tree and Graph Functions

Function Description

dfs(node) Depth-first traversal (preorder, inorder, postorder).

bfs(root) Breadth-first traversal using a queue.

networkx.add_edge(u, v) Adds an edge to a graph (using networkx).

networkx.shortest_path(graph, source, target) Finds the shortest path between two nodes.

📌 8. General Utility Functions

Function Description

enumerate(iterable) Returns index-value pairs.

zip(iter1, iter2) Pairs elements from iterables.

map(func, iterable) Applies a function to all elements.

filter(func, iterable) Filters elements based on a function.


Function Description

all(iterable) Returns True if all elements are true.

any(iterable) Returns True if at least one element is true.

bin(num) Converts an integer to binary.

int(binary_string, 2) Converts binary to an integer.

hex(num) Converts an integer to hexadecimal.

oct(num) Converts an integer to octal.

round(num, digits) Rounds a number.

💡 Summary

 Strings → Manipulation (.lower(), .replace(), sorted(s), Counter(s)).

 Lists & Arrays → Sorting, inserting, reversing, counting.

 Sets & Dictionaries → Lookup, merging, unique elements.

 Trees & Graphs → DFS, BFS, adjacency lists.

 General Utilities → zip(), map(), bin(), filter().

You might also like