|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "Preparation Work\n", |
| 8 | + "\n", |
| 9 | + "Please visit: https://www.python.org/downloads/ download the latest Python and tools\n", |
| 10 | + "Python version: 3.5.2 and 2.7.12\n", |
| 11 | + "\n", |
| 12 | + "Why we study Python\n", |
| 13 | + "\n", |
| 14 | + "Top-ranked CS departments at MIT and UC Berkeley recently switched their introductory courses to Python. \n", |
| 15 | + "The largest three MOOC providers (edX, Coursera, and Udacity) all offer introductory programming courses in Python. \n", |
| 16 | + "And professors in diverse subfields (e.g., Lorena Barba) are now advocating for teaching Python to novices.\n", |
| 17 | + "\n", |
| 18 | + "Shortcut of programming\n", |
| 19 | + "\n", |
| 20 | + "世界观和人生观\n", |
| 21 | + "天赋\n", |
| 22 | + "勤奋\n", |
| 23 | + "阅读\n", |
| 24 | + "实践,实践,再实践\n", |
| 25 | + "搜索技巧\n", |
| 26 | + "\n", |
| 27 | + "\n", |
| 28 | + "Python 简介\n", |
| 29 | + "基本变量概念\n", |
| 30 | + "Print() 和 Input() 用法\n", |
| 31 | + "Python IDLE 用法\n", |
| 32 | + "交互式 python 环境 Juypter 介绍\n", |
| 33 | + "\n", |
| 34 | + "about LISTS\n", |
| 35 | + "\n", |
| 36 | + "“Lists are mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application).” \n", |
| 37 | + "Very powerful, can store many kinds of real world data \n", |
| 38 | + "Create list\n", |
| 39 | + "Add an item\n", |
| 40 | + "Delete an item\n", |
| 41 | + "Sort\n", |
| 42 | + "Multidimensional\n", |
| 43 | + "Save and load\n", |
| 44 | + "\n", |
| 45 | + "Homework\n", |
| 46 | + "What can PRINT() statement do? please name an example of a relatively complicated coding\n", |
| 47 | + "If you were asked to develop an XPRINT statement in order to extend current one, which functions do you think need to be improved or added?\n", |
| 48 | + "Group assignment\n", |
| 49 | + "\n", |
| 50 | + "\n" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": 1, |
| 56 | + "metadata": { |
| 57 | + "collapsed": false |
| 58 | + }, |
| 59 | + "outputs": [ |
| 60 | + { |
| 61 | + "name": "stdout", |
| 62 | + "output_type": "stream", |
| 63 | + "text": [ |
| 64 | + "100\n", |
| 65 | + "100\n" |
| 66 | + ] |
| 67 | + } |
| 68 | + ], |
| 69 | + "source": [ |
| 70 | + "print(100)\n", |
| 71 | + "\n", |
| 72 | + "a = 100\n", |
| 73 | + "print(a)" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": null, |
| 79 | + "metadata": { |
| 80 | + "collapsed": true |
| 81 | + }, |
| 82 | + "outputs": [], |
| 83 | + "source": [ |
| 84 | + "print(100, 200, 300)" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": null, |
| 90 | + "metadata": { |
| 91 | + "collapsed": true |
| 92 | + }, |
| 93 | + "outputs": [], |
| 94 | + "source": [ |
| 95 | + "name = input('name:')\n", |
| 96 | + "print( 'hello', name)" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": null, |
| 102 | + "metadata": { |
| 103 | + "collapsed": true |
| 104 | + }, |
| 105 | + "outputs": [], |
| 106 | + "source": [ |
| 107 | + "a = 10\n", |
| 108 | + "if a > 10:\n", |
| 109 | + " print('big')\n", |
| 110 | + "else:\n", |
| 111 | + " print('small')" |
| 112 | + ] |
| 113 | + }, |
| 114 | + { |
| 115 | + "cell_type": "code", |
| 116 | + "execution_count": null, |
| 117 | + "metadata": { |
| 118 | + "collapsed": true |
| 119 | + }, |
| 120 | + "outputs": [], |
| 121 | + "source": [ |
| 122 | + "for i in range(10):\n", |
| 123 | + " print(i)" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "metadata": { |
| 130 | + "collapsed": true |
| 131 | + }, |
| 132 | + "outputs": [], |
| 133 | + "source": [ |
| 134 | + "a = ['pig', 'cat', 'dog']\n", |
| 135 | + "print(a)\n", |
| 136 | + "print(a[0])\n", |
| 137 | + "print(a[-1])" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "code", |
| 142 | + "execution_count": null, |
| 143 | + "metadata": { |
| 144 | + "collapsed": true |
| 145 | + }, |
| 146 | + "outputs": [], |
| 147 | + "source": [ |
| 148 | + "a.append('snake')\n", |
| 149 | + "print(a)\n", |
| 150 | + "\n", |
| 151 | + "a.pop(1)\n", |
| 152 | + "print(a)\n", |
| 153 | + "\n", |
| 154 | + "a.remove('dog')\n", |
| 155 | + "print(a)\n", |
| 156 | + "\n", |
| 157 | + "a = ['pig', 'cat', 'dog', 'snake', 'snake']\n", |
| 158 | + "a.sort()\n", |
| 159 | + "print(a)\n", |
| 160 | + "\n", |
| 161 | + "b = ['cat1', 'cat2', 'cat3']\n", |
| 162 | + "a.append(b)\n", |
| 163 | + "print(a)\n", |
| 164 | + "\n", |
| 165 | + "import pickle\n", |
| 166 | + "f = open('list_dump.txt', 'wb')\n", |
| 167 | + "a = ['pig', 'cat', 'dog', 'snake', 'snake']\n", |
| 168 | + "pickle.dump(a, f)\n", |
| 169 | + "f.close()\n", |
| 170 | + "\n", |
| 171 | + "f = open('list_dump.txt', 'rb')\n", |
| 172 | + "a1 = pickle.load(f)\n", |
| 173 | + "f.close()\n", |
| 174 | + "print(a1)\n", |
| 175 | + "\n", |
| 176 | + "a = ['pig', 'cat', 'dog', 'dog']\n", |
| 177 | + "a1 = [x for x in a if a.count(x) <= 1]\n", |
| 178 | + "print(a1)" |
| 179 | + ] |
| 180 | + } |
| 181 | + ], |
| 182 | + "metadata": { |
| 183 | + "kernelspec": { |
| 184 | + "display_name": "Python 3", |
| 185 | + "language": "python", |
| 186 | + "name": "python3" |
| 187 | + }, |
| 188 | + "language_info": { |
| 189 | + "codemirror_mode": { |
| 190 | + "name": "ipython", |
| 191 | + "version": 3 |
| 192 | + }, |
| 193 | + "file_extension": ".py", |
| 194 | + "mimetype": "text/x-python", |
| 195 | + "name": "python", |
| 196 | + "nbconvert_exporter": "python", |
| 197 | + "pygments_lexer": "ipython3", |
| 198 | + "version": "3.5.1" |
| 199 | + } |
| 200 | + }, |
| 201 | + "nbformat": 4, |
| 202 | + "nbformat_minor": 0 |
| 203 | +} |
0 commit comments