Python Builtins Flashcards

All the python builtin functions

1
Q

abs()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

all()

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

any()

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ascii()

A

Returns printable string representation with escapes. Common args: object. Time: O(n). Interview tip: Useful for debugging when dealing with Unicode strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

bin()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

bool()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

breakpoint()

A

Enters debugger. No args. Time: N/A. Interview tip: Quick way to debug during interviews if allowed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

bytearray()

A

Creates mutable sequence of bytes. Common args: string with encoding. Time: O(n). Interview tip: Used when you need to modify binary data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

bytes()

A

Creates immutable sequence of bytes. Common args: string with encoding. Time: O(n). Interview tip: Used for handling binary data in network protocols

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

callable()

A

Checks if object can be called. Common args: any object. Time: O(1). Interview tip: Check if object is function: callable(func)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

chr()

A

Converts integer to Unicode character. Common args: integer (0-1114111). Time: O(1). Interview tip: Used with ord() for character manipulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

classmethod()

A

Converts function to class method. Common args: function. Time: O(1). Interview tip: Rarely used in interviews

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

compile()

A

Compiles source into code object. Common args: source string. Time: O(n). Interview tip: Rarely used in interviews

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

complex()

A

Creates complex number. Common args: real/imag parts. Time: O(1). Interview tip: Rarely used in interviews except math problems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

delattr()

A

Deletes named attribute. Common args: object name. Time: O(1). Interview tip: getattr/setattr/delattr for dynamic attribute manipulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

dict()

A

Creates dictionary. Common args: mapping/iterable of pairs. Time: O(n). Interview tip: dict(zip(keys nums)) to create dict from parallel lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

dir()

A

Lists attributes of object. Common args: object. Time: O(1). Interview tip: Useful for debugging in interactive sessions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

divmod()

A

Returns quotient and remainder. Common args: two numbers. Time: O(1). Interview tip: Efficient way to get both // and % results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

enumerate()

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

eval()

A

Evaluates string as Python expression. Common args: expression string. Time: varies. Interview tip: Rarely used in interviews security risk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

exec()

A

Executes string as Python code. Common args: code string. Time: varies. Interview tip: Rarely used in interviews security risk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

filter()

A

Creates iterator of filtered elements. Common args: function iterable. Time: O(n). Interview tip: list(filter(None nums)) removes falsy values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

float()

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

format()

A

Formats value using format spec. Common args: value spec. Time: O(n). Interview tip: Useful for string formatting in output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
frozenset()
Creates immutable set. Common args: iterable. Time: O(n). Interview tip: Used when you need hashable set for dict keys
26
getattr()
Gets named attribute. Common args: object name default. Time: O(1). Interview tip: getattr(obj 'attr' default) safer than obj.attr
27
globals()
Returns dictionary of global namespace. No args. Time: O(1). Interview tip: Rarely used in interviews
28
hasattr()
Checks if object has attribute. Common args: object name. Time: O(1). Interview tip: Safe way to check for attribute existence
29
hash()
Returns hash value of object. Common args: hashable object. Time: O(1). Interview tip: Understanding hashability is key for dict/set usage
30
help()
Invokes help system. Common args: object. Time: O(1). Interview tip: Useful in interactive sessions not interviews
31
hex()
Converts integer to hex string. Common args: integer. Time: O(log n). Interview tip: Useful for bit manipulation [2:] removes '0x'
32
id()
Returns object's memory address. Common args: object. Time: O(1). Interview tip: Understanding object identity vs equality
33
input()
Reads line from input. Common args: prompt string. Time: O(n). Interview tip: Rarely used in coding interviews
34
int()
Converts to integer. Common args: number/string base=10. Time: O(n) for string. Interview tip: int('101' 2) for binary conversion
35
isinstance()
Checks if object is instance of class. Common args: object class/tuple. Time: O(1). Interview tip: isinstance(x (int float)) for multiple types
36
issubclass()
Checks if class is subclass. Common args: two classes. Time: O(1). Interview tip: Rarely used in interviews
37
iter()
Creates iterator from iterable. Common args: iterable sentinel. Time: O(1). Interview tip: Custom iteration with sentinel: iter(func sentinel)
38
len()
Returns length of sequence. Common args: sequence. Time: O(1). Interview tip: Check empty sequences: if not len(seq) or if not seq
39
list()
Creates list. Common args: iterable. Time: O(n). Interview tip: list() vs [] for empty list copy using list(original)
40
locals()
Returns dictionary of local namespace. No args. Time: O(1). Interview tip: Rarely used in interviews
41
map()
Applies function to iterable elements. Common args: function iterable. Time: O(n). Interview tip: map(int nums) converts strings to ints
42
max()
Returns maximum value. Common args: iterable or arguments key=func default. Time: O(n). Interview tip: max(nums default=float('-inf')) handles empty
43
min()
Returns minimum value. Common args: iterable or arguments key=func default. Time: O(n). Interview tip: min(nums default=float('inf')) handles empty
44
next()
Gets next item from iterator. Common args: iterator default. Time: O(1). Interview tip: Handle StopIteration with default: next(iter default)
45
object()
Creates featureless object. No args. Time: O(1). Interview tip: Rarely used in interviews
46
oct()
Converts integer to octal string. Common args: integer. Time: O(log n). Interview tip: Rarely used except specific base conversion problems
47
open()
Opens file. Common args: filename mode encoding. Time: O(1). Interview tip: Rarely used in coding interviews
48
ord()
Converts character to Unicode integer. Common args: single character. Time: O(1). Interview tip: ASCII math: ord('a') - ord('a') = 0
49
pow()
Returns base**exp [mod]. Common args: base exp [mod]. Time: O(log n) for integers. Interview tip: pow(base exp mod) more efficient than (base**exp)%mod
50
print()
Prints objects. Common args: objects sep=' ' end='\\n'. Time: O(n). Interview tip: print(x end='') for no newline
51
property()
Creates managed attribute. Common args: fget fset fdel doc. Time: O(1). Interview tip: Rarely used in interviews
52
range()
Creates sequence of numbers. Common args: stop or start stop [step]. Time: O(1) to create. Interview tip: Memory efficient vs list saves space
53
repr()
Returns printable representation. Common args: object. Time: O(n). Interview tip: Useful for debugging object representations
54
reversed()
Returns reverse iterator. Common args: sequence. Time: O(1) to create. Interview tip: Efficient way to iterate backwards
55
round()
Rounds number. Common args: number ndigits=0. Time: O(1). Interview tip: Beware floating point: round(2.5) = 2 round(3.5) = 4
56
set()
Creates set. Common args: iterable. Time: O(n). Interview tip: Quick way to get unique elements time complexity tradeoff
57
setattr()
Sets named attribute. Common args: object name value. Time: O(1). Interview tip: Dynamic attribute setting with setattr(obj 'attr' val)
58
slice()
Creates slice object. Common args: stop or start stop [step]. Time: O(1). Interview tip: Advanced slicing: s[slice(1 None 2)] vs s[1::2]
59
sorted()
Returns new sorted list. Common args: iterable key=func reverse=False. Time: O(n log n). Interview tip: sorted(nums key=abs) for absolute value sort
60
str()
Converts to string. Common args: object encoding errors. Time: O(n). Interview tip: str(123).zfill(4) for zero-padding
61
sum()
Sums numbers. Common args: iterable start=0. Time: O(n). Interview tip: sum(nums start=0.0) for float sum avoid start=[] for concatenation
62
super()
Returns proxy object for delegation. Common args: type object. Time: O(1). Interview tip: Rarely used in interviews
63
tuple()
Creates tuple. Common args: iterable. Time: O(n). Interview tip: Immutable sequences hashable as dict keys
64
type()
Returns type or creates new type. Common args: object. Time: O(1). Interview tip: type(x) is int vs isinstance(x int) for exact vs inheritance
65
vars()
Returns __dict__ attribute. Common args: object. Time: O(1). Interview tip: Debugging object attributes
66
zip()
Aggregates iterables. Common args: iterables. Time: O(1) to create O(n) to consume. Interview tip: zip(*matrix) for matrix transpose