Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Expanded List of Additional Built-In Functions

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)
5 views

Expanded List of Additional Built-In Functions

Uploaded by

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

Here’s an expanded list of additional built-in functions, methods, and useful operations available in

Python.

Additional Built-in Functions:


1. Advanced Iterators and Generators:
iter() : Returns an iterator object.

next() : Retrieves the next item from an iterator.

2. Functional Programming Tools:


lambda : Creates an anonymous function (inline function).

reduce() : Reduces an iterable to a single value by applying a function (available


in functools module).
functools.partial() : Allows partial function application, creating a new function with some
arguments pre-filled.
3. Advanced Type Conversion:
ord() : Converts a character to its ASCII/unicode value.

chr() : Converts an ASCII/unicode value to its character equivalent.

ascii() : Returns a string with a printable representation of an object.

repr() : Returns a string representation of an object (used for debugging).

frozenset() : Converts a collection to an immutable set.

4. Modules and Attributes:


__import__() : Imports a module programmatically, similar to the import statement.

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

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

vars() : Returns __dict__ attribute for a module, class, instance, or any other object with
attributes.
5. Memory-related Functions:
memoryview() : Creates a view object that exposes a buffer's data.

bytearray() : Returns an array of bytes.

bytes() : Converts an object to an immutable bytes object.

6. Specialized Mathematical Functions:


hex() : Converts an integer to hexadecimal.

bin() : Converts an integer to binary.

oct() : Converts an integer to octal.

complex() : Creates a complex number.

round() : Rounds a number to a specified number of decimal places.

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

7. Sorting and Reordering:


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

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

sorted() : Returns a sorted list from the given iterable.

8. Utility Functions:
slice() : Returns a slice object.

format() : Formats a value according to a format specifier.

id() : Returns the identity (unique integer) of an object.

compile() : Compiles a string of Python code into bytecode for execution.


Additional Common String Methods:
startswith() : Returns True if the string starts with the specified value.

endswith() : Returns True if the string ends with the specified value.

strip() : Removes leading and trailing spaces (or other specified characters).

lstrip() : Removes leading spaces (or specified characters).

rstrip() : Removes trailing spaces (or specified characters).

isalpha() : Returns True if the string consists of only alphabetic characters.

isdigit() : Returns True if the string consists of only digits.

islower() : Returns True if all alphabetic characters in the string are lowercase.

isupper() : Returns True if all alphabetic characters in the string are uppercase.

count() : Returns the number of occurrences of a substring.

partition() : Splits the string at the first occurrence of the separator and returns a tuple.

rpartition() : Splits the string at the last occurrence of the separator and returns a tuple.

Additional List Methods:


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

clear() : Removes all items from the list.

index() : Returns the index of the first occurrence of a value.

count() : Returns the number of occurrences of a value.

sort() : Sorts the list in place.

reverse() : Reverses the list in place.

Additional Dictionary Methods:


pop() : Removes the item with the specified key and returns its value.

popitem() : Removes and returns the last inserted key-value pair.

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

clear() : Removes all elements from the dictionary.

setdefault() : Returns the value of the specified key. If the key does not exist, inserts the key with
the specified value.

Additional Set Methods:


discard() : Removes an element from a set if it is present.

pop() : Removes and returns an arbitrary element from the set.

issubset() : Checks if one set is a subset of another.


issuperset() : Checks if one set is a superset of another.

difference_update() : Removes all elements of another set from the original set.

symmetric_difference() : Returns the symmetric difference of two sets (elements that are in
either set, but not both).

Advanced Python Concepts:


1. Decorators:
@staticmethod : Used to define static methods that don't access or modify the class state.

@classmethod : Used to define class methods that take the class as the first parameter.

@property : Defines a method as a property, allowing it to be accessed like an attribute.

2. Context Managers:
with : Used for wrapping the execution of a block of code in methods defined by context
managers (e.g., file operations).
3. Custom Exceptions:
You can define custom exceptions by subclassing Python’s built-in Exception class:

python Copy code

class MyCustomError(Exception): pass

4. Comprehensions:
List comprehensions:
python Copy code

squares = [x**2 for x in range(10)]

Dictionary comprehensions:
python Copy code

squares_dict = {x: x**2 for x in range(10)}

Set comprehensions:
python Copy code

squares_set = {x**2 for x in range(10)}

5. Generators:
Used to create iterators with a sequence of values. A generator yields values using
the yield keyword.

python Copy code

def my_generator(): for i in range(5): yield i


This extended list covers more specialized functions, methods, and Pythonic concepts for both
beginners and advanced users, enhancing the ability to write more efficient and readable code.

You might also like