{
"metadata": {
"name": "",
"signature": "sha256:3d8e168c53b333482ede8c41b34f62222e7a07d410c6665c60f32285923930fa"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"PyLadies San Diego and"
]
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"San Diego Python User Group"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"present"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Introduction to Python"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"#Welcome to Intro to Python!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you haven't already, please complete the short setup instructions at:\n",
"http://bit.ly/intro-setup"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Please also visit:\n",
"http://codeacademy.com\n",
" \n",
"and create an account."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After completing these steps, you should:\n",
"* Have Python installed\n",
"* Be able to enter and exit Python\n",
"* Have a Codeacademy account\n",
"\n",
"Raise your hand (or place a yellow sticky note on your screen), if you need help.\n"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"The Game plan"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Introductions, motivation\n",
"* Interactive lecture: first steps with Python\n",
"* Practice\n",
"\n",
"\n",
"* Interactive lecture: lists and loops\n",
"* Practice\n",
"* Wrap-up and next steps"
]
},
{
"cell_type": "heading",
"level": 6,
"metadata": {},
"source": [
"5 min Why Python is so great? (7 slides) while audience checks config"
]
},
{
"cell_type": "heading",
"level": 6,
"metadata": {},
"source": [
"10 min Let's get started with the interactive lecture"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Terminal and start python"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 + 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1.4 + 2.25"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"4 - 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 * 3"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"4 / 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1 / 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Whole number 1 divided by whole number 2"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1.0 / 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 + 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2+2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"(1 + 3) * 4"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = 4"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x * 3"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Variables"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cups_of_flour = 5"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cups_of_flour * .5"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1 / 2\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1.0 / 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Two different data types\n",
"\n",
"\n",
"Let's use a function"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(1)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(1.0)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Questions?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"String data type"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Python, I'm your #1 fan!\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(\"Hello\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"name = \"Carol\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 + 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Carol\" + \"Willing\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Carol \" + \"Willing\"\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Carol\" + \" \" + \"Willing\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"name = \"Carol\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"My name is \" + name"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tip - arrow up save typing"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\" + 1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\" + \"1\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(1)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(\"1\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\" + str(1)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"len(\"Hello\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"len(name)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"The length of my name is \" + str(len(name))"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"'Hello'\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Python, I'm your #1 fan!\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"A\" * 40"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"h = \"Happy\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"b = \"Birthday\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"(h + b) * 10"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Printing - interactive vs file"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"Hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"Hello\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Questions?"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"3 ** 3"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(1)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(1.0)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(\"1\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make choices"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"True"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"False"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(True)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(False)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"0 == 0"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"0 == 1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"0 != 1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"a\" == \"A\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1 > 0"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"2 >= 3"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"-1<0"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
".5 <= 1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"H\" in \"Hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"x\" in \"Hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"a\" not in \"abcde\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(True)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(\"True\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"type(true)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = 4"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x == 4"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if 6 > 5:\n",
" print(\"Six is greater than 5\")\n",
" "
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if 0 > 2:\n",
" print(\"Zero is greater\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if \"banana\" in \"bananarama\":\n",
" print(\"I miss the 80s\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One of two actions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"sister = 15"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"brother = 12"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if sister > brother:\n",
" print(\"Sister is older\")\n",
"else:\n",
" print(\"Brother is older\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1 > 0 and 1 < 2"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1 < 2 and \"x\" in \"abc\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"a\" in \"abc\" and \"b\" in \"abc\" and \"c\" in \"abc\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\"a\" in \"hello\" or \"e\" in \"hello\""
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"temp = 32"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if temp > 60 and temp < 75:\n",
" print(\"Nice and cozy\")\n",
"else:\n",
" print(\"Too extreme for me\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One of three things"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"sister = 15\n",
"brother = 15\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if sister > brother:\n",
" print(\"Sister is older\")\n",
"elif sister == brother:\n",
" print(\"Twinsies!!\")\n",
"else:\n",
" print(\"Brother is older\")"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Questions? 47 min mark"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Practice problems - Codeacademy practice\n",
"Strings and choices\n",
"http://bit.ly/py-practice"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import YouTubeVideo\n",
"# a tutorial about Python at PyCon 2014 in Montreal, Canada by Jessica McKellar\n",
"# Credit: William Stein.\n",
"YouTubeVideo('MirG-vJOg04')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
" \n",
" "
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
""
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import IFrame\n",
"# Pull in the tutorial prep information from OpenHatch wiki\n",
"IFrame('http://bit.ly/intro-setup', width='100%', height=350)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
" \n",
" "
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
""
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}