Category: Code

  • Libraries, packages, and modules

    A library is a corpus of reusable code modules and their accompanying documentation. Libraries are bundled into packages that you install, which can then be imported into your coding environment as needed. You’ll typically encounter the terms “library” and “package” used interchangeably. Modules are similar to libraries, in that they are groups of related classes…

  • Reference guide: Sets

    A set is a collection of unique data elements, without duplicates. # creates a set with the elements 5, 10, 10, and 20.my_set = {5, 10, 10, 20} empty_set = set() # create an empty setSets can only contain hashable (immutable) types like numbers, strings, and tuples. You cannot add lists or dictionaries to a…

  • Reference guide: Dictionaries

    There are two main ways to create dictionaries in Python: When instantiating a dictionary using braces, separate each element with a colon. For example, the following code creates a dictionary containing continents as keys and their smallest countries as values: To create an empty dictionary, use empty braces or the dict() function: The dict() function…

  • zip(), enumerate(), and list comprehension

    zip() The zip() function is a built-in Python function that does what the name implies: It performs an element-wise combination of sequences.  The function returns an iterator that produces tuples containing elements from each of the input sequences. An iterator is an object that enables processing of a collection of items one at a time…

  • Reference guide: Lists

    To create an empty list, use empty brackets or the list() function: List mutability Lists are mutable, which means that you can change their contents after they are created. List operations Lists can be combined using the addition operator (+): They can also be multiplied using the multiplication operator (*): But they cannot be subtracted…

  • String indexing and slicing

    Indexing and slicing are powerful tools in Python that allow you to access specific elements or parts of a sequence. Both indexing and slicing use square brackets. Remember that in a slice the starting index is inclusive and the stopping index is exclusive, and that negative indices count from the end of the sequence

  • Loops, break, and continue

    A while loop allows you to repeatedly execute a block of code while a certain condition is true. You can use the break statement to exit the loop prematurely, and the continue statement to skip to the next iteration of the loop without executing the rest of the code in the current iteration. A for…

  • The Zen of Python

    Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the…

  • Built-in Functions

    The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.

  • Jupyter notebook

    The Jupyter Notebook is a web-based interactive computing platform.