Python Builtins Flashcards
All the python builtin functions
abs()
Returns absolute value. Common args: numbers (int/float). Returns same type as input. Time: O(1). Interview tip: Often used with differences like abs(target - current) <= epsilon for float comparisons
all()
Returns True if all elements are truthy. Common args: iterable. Time: O(n). Returns True for empty iterables. Interview tip: Use with generator expressions like all(x > 0 for x in nums)
any()
Returns True if any element is truthy. Common args: iterable. Time: O(n). Short-circuits on first True. Interview tip: Quick way to check if any element meets condition: any(x in target for x in nums)
ascii()
Returns printable string representation with escapes. Common args: object. Time: O(n). Interview tip: Useful for debugging when dealing with Unicode strings
bin()
Converts integer to binary string with ‘0b’ prefix. Common args: integer. Time: O(log n). Interview tip: Use [2:] to remove ‘0b’ prefix. For bit manipulation problems
bool()
Converts value to boolean. Common args: any value. Time: O(1). Empty sequences/mappings return False. Interview tip: bool([]) is False; bool([0]) is True
breakpoint()
Enters debugger. No args. Time: N/A. Interview tip: Quick way to debug during interviews if allowed
bytearray()
Creates mutable sequence of bytes. Common args: string with encoding. Time: O(n). Interview tip: Used when you need to modify binary data
bytes()
Creates immutable sequence of bytes. Common args: string with encoding. Time: O(n). Interview tip: Used for handling binary data in network protocols
callable()
Checks if object can be called. Common args: any object. Time: O(1). Interview tip: Check if object is function: callable(func)
chr()
Converts integer to Unicode character. Common args: integer (0-1114111). Time: O(1). Interview tip: Used with ord() for character manipulation
classmethod()
Converts function to class method. Common args: function. Time: O(1). Interview tip: Rarely used in interviews
compile()
Compiles source into code object. Common args: source string. Time: O(n). Interview tip: Rarely used in interviews
complex()
Creates complex number. Common args: real/imag parts. Time: O(1). Interview tip: Rarely used in interviews except math problems
delattr()
Deletes named attribute. Common args: object name. Time: O(1). Interview tip: getattr/setattr/delattr for dynamic attribute manipulation
dict()
Creates dictionary. Common args: mapping/iterable of pairs. Time: O(n). Interview tip: dict(zip(keys nums)) to create dict from parallel lists
dir()
Lists attributes of object. Common args: object. Time: O(1). Interview tip: Useful for debugging in interactive sessions
divmod()
Returns quotient and remainder. Common args: two numbers. Time: O(1). Interview tip: Efficient way to get both // and % results
enumerate()
Creates iterator of (index value) pairs. Common args: iterable start=0. Time: O(1) to create O(n) to consume. Interview tip: Get indices while iterating: for i x in enumerate(nums)
eval()
Evaluates string as Python expression. Common args: expression string. Time: varies. Interview tip: Rarely used in interviews security risk
exec()
Executes string as Python code. Common args: code string. Time: varies. Interview tip: Rarely used in interviews security risk
filter()
Creates iterator of filtered elements. Common args: function iterable. Time: O(n). Interview tip: list(filter(None nums)) removes falsy values
float()
Converts to float. Common args: number/string. Time: O(1). Common special args: float(‘inf’) float(‘-inf’) for infinity. Interview tip: Use inf as default for min/max tracking
format()
Formats value using format spec. Common args: value spec. Time: O(n). Interview tip: Useful for string formatting in output