{"metadata": {"signature": "sha256:bd5c50ce5315bb5cfe15498aed9b3109f444ab2e3035c06901c5edaa69ab4ec2", "name": ""}, "nbformat_minor": 0, "nbformat": 3, "worksheets": [{"metadata": {}, "cells": [{"metadata": {}, "cell_type": "markdown", "source": ["# Python Introduction: Types"]}, {"metadata": {}, "cell_type": "markdown", "source": ["Let's evaluate some simple expressions."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["3*2"], "prompt_number": 1, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 1, "text": ["6"]}]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["5+3*2"], "prompt_number": 2, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 2, "text": ["11"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["You can use `type()` to find the *type* of an expression."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["type(5+3*2)"], "prompt_number": 3, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 3, "text": ["int"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["Now add decimal points."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["5+3.5*2"], "prompt_number": 4, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 4, "text": ["12.0"]}]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["type(5+3.0*2)"], "prompt_number": 5, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 5, "text": ["float"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["Strings are written with single (``'``) or double quotes (`\"`)"]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["\"hello\""], "prompt_number": 6, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 6, "text": ["'hello'"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["Multiplication and addition work on strings, too."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["3 * 'hello' + \"eagpggpu\""], "prompt_number": 7, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 7, "text": ["'hellohellohelloeagpggpu'"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["Lists are written in brackets (`[]`) with commas (`,`)."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["[5, 3, 7]"], "prompt_number": 8, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 8, "text": ["[5, 3, 7]"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["List entries don't have to have the same type."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["[\"hi there\", 15, [1,2,3]]"], "prompt_number": 9, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 9, "text": ["['hi there', 15, [1, 2, 3]]"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["\"Multiplication\" and \"addition\" work on lists, too."]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["[1,2,3] * 4 + [5, 5, 5]"], "prompt_number": 10, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 10, "text": ["[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 5, 5, 5]"]}]}, {"metadata": {}, "cell_type": "markdown", "source": ["Hmmmmmm. Was that what you expected?"]}, {"collapsed": false, "cell_type": "code", "language": "python", "input": ["import numpy as np\n", "\n", "np.array([1,2,3]) * 4 + np.array([5,5,5])"], "prompt_number": 11, "metadata": {}, "outputs": [{"output_type": "pyout", "metadata": {}, "prompt_number": 11, "text": ["array([ 9, 13, 17])"]}]}]}]}