v1.0.0CPython 3.x ยท Built-in Functions

builtins.quiz()

len, sorted, zip, enumerate, map, filter โ€” these show up in nearly every Python interview. Drill every built-in so none catch you off guard when the clock is ticking.

// how to use this quizType ONLY the function call โ€” e.g. len(lst) โ€” include parentheses and argsCheck each question as you go OR submit everything at the endStuck? Hit Explain or Reveal on any questionUse the tag chips below to filter by topic
Score0 / 72
Streak๐Ÿ”ฅ 0
This Q0:00
Total0:00
// filter by topic ย ยทย  showing 72 of 72
Question 01 / 72โ˜…constructor

Given the string "42", write the call that converts it to the integer 42.

>>>
Question 02 / 72constructor

Given the string "3.14", write the call that converts it to the float 3.14.

>>>
Question 03 / 72โ˜…constructor

Given the integer 42, write the call that converts it to the string "42".

>>>
Question 04 / 72constructor

Given the integer 1, write the call that converts it to a boolean True.

>>>
Question 05 / 72constructor

Given t = (1, 2, 3), write the call that converts it to the list [1, 2, 3].

>>>
Question 06 / 72constructor

Given lst = [1, 2, 3], write the call that converts it to the tuple (1, 2, 3).

>>>
Question 07 / 72โ˜…constructor

Given lst = [1, 2, 2, 3], write the call that converts it to the set {1, 2, 3}.

>>>
Question 08 / 72constructor

Given lst = [1, 2, 3], write the call that builds an immutable frozenset from it.

>>>
Question 09 / 72โ˜…constructor

Given pairs = [("a", 1), ("b", 2)], write the call that builds the dict {"a": 1, "b": 2}.

>>>
Question 10 / 72constructor

Given the string "hello", write the call that converts it to a UTF-8 encoded bytes object.

>>>
Question 11 / 72constructor

Given lst = [65, 66, 67], write the call that builds a mutable bytearray from it.

>>>
Question 12 / 72constructor

Write the call that constructs a base object instance with no arguments.

>>>
Question 13 / 72constructor

Given lst = [10, 20, 30], write the call that creates a memoryview over a bytes object built from it. (Use bytes(...) as the argument.)

>>>
Question 14 / 72constructor

Write the call that builds a slice object representing [1:10:2].

>>>
Question 15 / 72โ˜…iteration

Given lst = [1, 2, 3] and the function str, write the call that returns an iterator yielding "1", "2", "3".

>>>
Question 16 / 72โ˜…iteration

Given lst = [1, 2, 3, 4], write the call that returns an iterator over only the even numbers (use a lambda).

>>>
Question 17 / 72โ˜…iteration

Given nums = [1, 2, 3] and letters = ["a", "b", "c"], write the call that returns an iterator yielding (1, "a"), (2, "b"), (3, "c").

>>>
Question 18 / 72โ˜…iteration

Given lst = ["a", "b", "c"], write the call that returns an iterator yielding (0, "a"), (1, "b"), (2, "c").

>>>
Question 19 / 72โ˜…iteration

Given lst = [3, 1, 4, 1, 5], write the call that returns the new sorted list [1, 1, 3, 4, 5].

>>>
Question 20 / 72โ˜…iteration

Given lst = [1, 2, 3], write the call that returns a reverse iterator over it.

>>>
Question 21 / 72โ˜…iteration

Write the call that produces a range object yielding 0, 1, 2, 3, 4.

>>>
Question 22 / 72iteration

Given lst = [1, 2, 3], write the call that returns an iterator over it.

>>>
Question 23 / 72iteration

Given an iterator it, write the call that returns the next item from it (raising StopIteration if exhausted).

>>>
Question 24 / 72iteration

Given an async iterable aiter_obj, write the call (Python 3.10+) that returns an async iterator over it.

>>>
Question 25 / 72iteration

Given an async iterator ait, write the call (Python 3.10+) that awaits the next item from it.

>>>
Question 26 / 72โ˜…math

Given the integer -5, write the call that returns its absolute value.

>>>
Question 27 / 72โ˜…math

Given lst = [3, 1, 4, 1, 5], write the call that returns the smallest element.

>>>
Question 28 / 72โ˜…math

Write the call that returns the smaller of 3 and 7, passing them as two separate arguments (not in a list).

>>>
Question 29 / 72โ˜…math

Given lst = [3, 1, 4, 1, 5], write the call that returns the largest element.

>>>
Question 30 / 72โ˜…math

Write the call that returns the larger of 3 and 7, passing them as two separate arguments (not in a list).

>>>
Question 31 / 72โ˜…math

Given lst = [1, 2, 3, 4], write the call that returns the sum 10.

>>>
Question 32 / 72math

Given the float 3.14159, write the call that rounds it to 2 decimal places.

>>>
Question 33 / 72math

Write the call that computes 2 ** 10 using the built-in (returns 1024).

>>>
Question 34 / 72math

Write the call that returns both the quotient and remainder of 17 / 5 as the tuple (3, 2).

>>>
Question 35 / 72โ˜…aggregate

Given flags = [True, True, False], write the call that returns False (because not every item is truthy).

>>>
Question 36 / 72โ˜…aggregate

Given flags = [False, False, True], write the call that returns True (because at least one item is truthy).

>>>
Question 37 / 72โ˜…aggregate

Given lst = [1, 2, 3], write the call that returns its length 3.

>>>
Question 38 / 72io

Write the call that prints "Hello, World!" to stdout.

>>>
Question 39 / 72io

Write the call that prompts the user with "Name: " and reads a line from stdin.

>>>
Question 40 / 72io

Write the call that opens the file "data.txt" for reading in text mode (default).

>>>
Question 41 / 72io

Given the float 3.14159, write the call that formats it with 2 decimal places using the format-spec mini-language (returns "3.14").

>>>
Question 42 / 72io

Given the string "hello", write the call that returns its quoted printable representation (e.g. "'hello'").

>>>
Question 43 / 72io

Given the string "hรฉllo", write the call that returns an ASCII-only repr with non-ASCII chars escaped.

>>>
Question 44 / 72introspection

Given the value 42, write the call that returns its type (<class 'int'>).

>>>
Question 45 / 72โ˜…introspection

Given the value 42, write the call that returns True if it is an instance of int.

>>>
Question 46 / 72introspection

Given the class bool, write the call that returns True because bool is a subclass of int.

>>>
Question 47 / 72introspection

Given the value x, write the call that returns its unique identity as an integer.

>>>
Question 48 / 72introspection

Given the string "hello", write the call that returns its hash value.

>>>
Question 49 / 72introspection

Given the value 42, write the call that returns a list of attribute names available on it.

>>>
Question 50 / 72introspection

Given an object obj, write the call that returns its __dict__ (the namespace mapping).

>>>
Question 51 / 72introspection

Given an object obj, write the call that returns its attribute named "name".

>>>
Question 52 / 72introspection

Given an object obj, write the call that sets its attribute "name" to "Ada".

>>>
Question 53 / 72introspection

Given an object obj, write the call that returns True if it has an attribute named "name".

>>>
Question 54 / 72introspection

Given an object obj, write the call that deletes its attribute named "name".

>>>
Question 55 / 72introspection

Given the function print, write the call that returns True because it is callable.

>>>
Question 56 / 72conversion

Given the integer 65, write the call that returns the corresponding character "A".

>>>
Question 57 / 72conversion

Given the character "A", write the call that returns its Unicode code point 65.

>>>
Question 58 / 72conversion

Given the integer 255, write the call that returns its hexadecimal string "0xff".

>>>
Question 59 / 72conversion

Given the integer 8, write the call that returns its octal string "0o10".

>>>
Question 60 / 72conversion

Given the integer 5, write the call that returns its binary string "0b101".

>>>
Question 61 / 72meta

Given the string expression "2 + 2", write the call that evaluates it and returns 4.

>>>
Question 62 / 72meta

Given the source string "x = 1", write the call that executes it as a statement (returns None).

>>>
Question 63 / 72meta

Given the source string "2 + 2", write the call that compiles it as an expression named "".

>>>
Question 64 / 72meta

Write the call that returns the current global symbol table as a dict.

>>>
Question 65 / 72meta

Write the call that returns the current local symbol table as a dict.

>>>
Question 66 / 72meta

Inside a method, write the call that returns a proxy object for delegating method calls to the parent class (no arguments).

>>>
Question 67 / 72meta

Write the call that creates a property descriptor from a getter function get_x.

>>>
Question 68 / 72meta

Write the call that wraps a function func as a class method (usually used as a decorator).

>>>
Question 69 / 72meta

Write the call that wraps a function func as a static method (usually used as a decorator).

>>>
Question 70 / 72meta

Write the call that imports the module named "math" dynamically (rarely used directly โ€” prefer importlib.import_module).

>>>
Question 71 / 72meta

Write the call (Python 3.7+) that drops into the configured debugger at the current line of code.

>>>
Question 72 / 72meta

Given the built-in str, write the call that opens its interactive help in the REPL.

>>>

// finished? submit your full attempt