Python Reference
Built-in functions and the methods of strings, lists, dictionaries and sets.
79 of 79
| Name | Group | Description |
|---|---|---|
| print() | Built-in | Prints values to the screen. |
| input() | Built-in | Reads a line typed by the user. |
| len() | Built-in | The number of items in a sequence or collection. |
| type() | Built-in | The type of a value. |
| int() | Built-in | Converts a value to an integer. |
| float() | Built-in | Converts a value to a decimal number. |
| str() | Built-in | Converts a value to a string. |
| bool() | Built-in | Converts a value to True or False. |
| list() | Built-in | Makes a list. |
| tuple() | Built-in | Makes a tuple. |
| set() | Built-in | Makes a set of unique values. |
| dict() | Built-in | Makes a dictionary. |
| range() | Built-in | A sequence of numbers. |
| sum() | Built-in | The sum of an iterable of numbers. |
| min() | Built-in | The smallest item. |
| max() | Built-in | The largest item. |
| abs() | Built-in | The absolute value. |
| round() | Built-in | Rounds a number. |
| pow() | Built-in | Raises to a power. |
| divmod() | Built-in | Quotient and remainder. |
| sorted() | Built-in | A new sorted list. |
| reversed() | Built-in | An iterator over items in reverse. |
| enumerate() | Built-in | Pairs each item with its index. |
| zip() | Built-in | Pairs items from several iterables. |
| map() | Built-in | Applies a function to every item. |
| filter() | Built-in | Keeps items where the function is true. |
| any() | Built-in | True if any item is true. |
| all() | Built-in | True if every item is true. |
| isinstance() | Built-in | Whether an object is of a type. |
| open() | Built-in | Opens a file. |
| str.upper() | String | Upper-case copy of a string. |
| str.lower() | String | Lower-case copy of a string. |
| str.title() | String | Capitalises each word. |
| str.strip() | String | Removes whitespace from both ends. |
| str.split() | String | Splits a string into a list. |
| str.join() | String | Joins items with a separator. |
| str.replace() | String | Replaces text. |
| str.find() | String | Index of the first match, or -1. |
| str.startswith() | String | Whether a string starts with text. |
| str.endswith() | String | Whether a string ends with text. |
| str.count() | String | Counts occurrences. |
| str.format() | String | Fills in placeholders. |
| str.isdigit() | String | Whether all characters are digits. |
| str.zfill() | String | Pads with zeros on the left. |
| list.append() | List | Adds an item to the end. |
| list.extend() | List | Adds all items of another iterable. |
| list.insert() | List | Inserts an item at an index. |
| list.remove() | List | Removes the first matching item. |
| list.pop() | List | Removes and returns an item. |
| list.sort() | List | Sorts the list in place. |
| list.reverse() | List | Reverses the list in place. |
| list.index() | List | The index of the first match. |
| list.count() | List | Counts occurrences. |
| list.copy() | List | A shallow copy. |
| dict.get() | Dictionary | A value, or a default if missing. |
| dict.keys() | Dictionary | The keys. |
| dict.values() | Dictionary | The values. |
| dict.items() | Dictionary | Key and value pairs. |
| dict.update() | Dictionary | Merges another dictionary in. |
| dict.pop() | Dictionary | Removes a key and returns its value. |
| dict.setdefault() | Dictionary | Gets a key, adding it if missing. |
| set.add() | Set | Adds an item. |
| set.union() | Set | All items from both sets. |
| set.intersection() | Set | Items in both sets. |
| set.difference() | Set | Items in a but not in b. |
| f-string | Syntax | A string with expressions inside braces. |
| list comprehension | Syntax | Builds a list in one line. |
| lambda | Syntax | A small anonymous function. |
| try / except | Syntax | Handles errors. |
| import | Syntax | Loads a module. |
| math.sqrt() | math | The square root. |
| math.ceil() | math | Rounds up. |
| math.floor() | math | Rounds down. |
| math.pi | math | The value of pi. |
| random.choice() | random | A random item from a sequence. |
| random.randint() | random | A random integer in a range. |
| datetime.date | datetime | Work with dates. |
| json.dumps() | json | Converts data to JSON text. |
| json.loads() | json | Converts JSON text to data. |