{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n" ] } ], "source": [ "# Boolean variables\n", "\n", "P = True\n", "Q = True\n", "R = False\n", "\n", "X = P == R # == returns a boolean value\n", "print(X)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True False False\n", "True\n", "False\n", "True\n", "True\n", "True\n" ] } ], "source": [ "print( P, not P, not(P) )\n", "\n", "print(P and Q) # return True only if both variables are True\n", "print(P and Q and R) # return True only if all 3 variables are True\n", "\n", "print(P or Q) # return True if any of the variables are True\n", "print(P or Q or R)\n", "print(R or Q or P) # order does not matter" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "True\n", "True\n" ] } ], "source": [ "print( P and Q or R ) # Ambiguous... use parentheses to clarify!\n", "print( (P and Q) or R )\n", "print( P and (Q or R) )" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 2 }