-{"worksheets": [{"metadata": {}, "cells": [{"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def the_function(var):\n", " \"\"\"This is a docstring, where a function definition might live\"\"\"\n", " a = 1 + var # this is a simple comment\n", " return a"], "metadata": {}, "language": "python", "prompt_number": 1}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " # first, retrieve the decay constants from the database\n", " mylist = database.decay_constants()\n", " # next, try to access an element of the list\n", " try:\n", " d = mylist[index] # gets decay constant at index in the list\n", " # if the index doesn't exist\n", " except IndexError:\n", " # throw an informative error message\n", " raise Exception(\"value not found in the list\")\n", " return d"], "metadata": {}, "language": "python", "prompt_number": 2}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " lambdas = database.decay_constants()\n", " try:\n", " lambda_i = lambdas[index] # gets decay constant at index in the list\n", " except IndexError:\n", " raise Exception(\"value not found in the list\")\n", " return lambda"], "metadata": {}, "language": "python", "prompt_number": 3}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def decay(index, database):\n", " lambdas = database.decay_constants()\n", " try:\n", " lambda_i = lambdas[index] # gets decay constant at index in the list\n", " except LookupError:\n", " raise Exception(\"value not found in the decay constants object\")\n", " return lambda"], "metadata": {}, "language": "python", "prompt_number": 4}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["# packages and modules are short and lowercase\n", "packages\n", "modules\n", "\n", "# other objects can be long\n", "ClassesUseCamelCase\n", "ExceptionsAreClassesToo\n", "functions_use_snake_case\n", "CONSTANTS_USE_ALL_CAPS\n", "\n", "# variable scope is *suggested* by style convention\n", "_single_leading_underscore_ # internal to module\n", "single_trailing_underscore_ # avoids conflicts with Python keywords\n", "__double_leading_and_trailing__ # these are magic, like __init__"], "metadata": {}, "language": "python", "prompt_number": 5}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def <name>(<args>):\n", " \"\"\"<docstring>\"\"\"\n", " <body>"], "metadata": {}, "language": "python", "prompt_number": 6}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["def power(base, x):\n", " \"\"\"Computes base^x. Both base and x should be integers,\n", " floats, or another numeric type.\n", " \"\"\"\n", " return base**x "], "metadata": {}, "language": "python", "prompt_number": 7}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": ["class Isotope(object):\n", " \"\"\"A class defining the data and behaviors of a radionuclide.\n", " \"\"\""], "metadata": {}, "language": "python", "prompt_number": 8}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": [".. function:: spin(self, s)\n", "\n", " Set the spin of the particle to the value, s.\n"], "metadata": {}, "language": "python", "prompt_number": 9}, {"cell_type": "code", "collapsed": false, "outputs": [], "input": [".. function:: spin(self, s)\n", "\n", " Set the spin of the particle to the value, s.\n", "\n", " :param s: the new spin value\n", " :type s: integer or float\n", " :rtype: None"], "metadata": {}, "language": "python", "prompt_number": 10}]}], "nbformat": 3, "nbformat_minor": 0, "metadata": {"name": "", "signature": "sha256:a507e2b4823427095ab936332e4a2258de07c758f87fbb5c5e55c94c3d5e481c"}}
0 commit comments