Built-in Function Registry

Built-in Functions

Built-in Function Registry

In this tutorial, we'll use a quick guide to choose the right built-in function for a task.

This is a quick use-case guide for common built-in functions.

Everyday Output and Input

| Function | Use case | Example | | --- | --- | --- | | print() | Show output | print("Hello") | | input() | Ask the user for text | name = input("Name: ") |

Conversion

| Function | Use case | Example | | --- | --- | --- | | int() | Convert to a whole number | int("42") | | float() | Convert to a decimal number | float("3.14") | | str() | Convert to text | str(99) | | bool() | Convert to true/false | bool("hello") |

Checking Values

| Function | Use case | Example | | --- | --- | --- | | type() | Inspect a value's type | type(42) | | isinstance() | Check a value's type | isinstance(42, int) |

Collections and Numbers

| Function | Use case | Example | | --- | --- | --- | | len() | Count items | len([1, 2, 3]) | | sum() | Add numbers | sum([1, 2, 3]) | | min() | Find smallest | min([4, 2, 9]) | | max() | Find largest | max([4, 2, 9]) | | sorted() | Return sorted values | sorted(["b", "a"]) | | enumerate() | Loop with indexes | for i, item in enumerate(items): | | range() | Generate numbers for loops | range(5) |

Choosing the Right Built-in

Ask what you are trying to do:

  • Need text from a user? input()
  • Need a number from text? int() or float()
  • Need to count items? len()
  • Need the biggest or smallest? max() or min()
  • Need sorted output? sorted()
  • Need positions in a loop? enumerate()

Practice

Choose five functions from the registry and write one small example for each.