├── 1-variable_string_number.ipynb ├── 10-files.ipynb ├── 11-figures.ipynb ├── 12-stat.ipynb ├── 2-list_tuple.ipynb ├── 3-dict_set.ipynb ├── 4-input_file.ipynb ├── 5-function_para.ipynb ├── 6-class.ipynb ├── 7-review.ipynb ├── 8-pandas.ipynb ├── 9-pandas_2.ipynb ├── CEPS.csv ├── ForestData.csv ├── ForestData.xlsx ├── Performance_MNR.xml ├── README.md ├── alice.txt ├── chinesetext.txt ├── coursework.ipynb ├── csv_mindex.csv ├── ex1.csv ├── ex1.xlsx ├── ex2.csv ├── ex2.xlsx ├── ex3.txt ├── ex4.csv ├── ex5.csv ├── ex6.csv ├── ex7.csv ├── example.json ├── exer1.ipynb ├── exer2.ipynb ├── exer3.ipynb ├── exer3.txt ├── exer4.ipynb ├── exer5.ipynb ├── exer6.ipynb ├── exer7.ipynb ├── exfriend.jpg ├── fdic_failed_bank_list.html ├── little_women.txt ├── movies.json ├── out.csv ├── out.txt ├── pi_digits.txt ├── pi_million_digits.txt ├── pipaxing.txt ├── programming.txt ├── siddhartha.txt ├── spx.csv └── tseries.csv /2-list_tuple.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# 数据结构\n", 12 | "\n", 13 | "\n", 14 | "- **list**(列表): 支持插入,弹出,索引,切片等\n", 15 | "\n", 16 | "\n", 17 | "- **tuple**(元组): 一经创建不可修改\n", 18 | "\n", 19 | "\n", 20 | "- **set**(集合): 交集,并集等操作\n", 21 | "\n", 22 | "\n", 23 | "- **dict**(字典): 无序的key-val健值对\n", 24 | "\n", 25 | "\n", 26 | "以上四种结构也可以相互嵌套, **list** 和 **dict**是最常用的两个结构。" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "slide" 34 | } 35 | }, 36 | "source": [ 37 | "# 列表" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## 列表创建\n", 45 | "\n", 46 | "\n", 47 | "+ 命名一个列表,如果你列表里都是同学的名字,就叫students\n", 48 | "+ python使用方括号指明列表,students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 49 | "+ range函数的使用\n", 50 | "+ 枚举法\n", 51 | "+ 空列表" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 2, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "[1, 2, 3, 4, 5]\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "numbers = list(range(1,6)) \n", 69 | "print(numbers) " 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 1, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "[1, 4, 7]\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "numbers = list(range(1,9,3)) \n", 87 | "print(numbers) " 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "[1, 1, 2, 3, 5, 8, 13, 21]\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "fibonacci_numbers = [1, 1, 2, 3, 5, 8, 13, 21] #斐波那契数\n", 105 | "print(fibonacci_numbers)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 4, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "name": "stdout", 115 | "output_type": "stream", 116 | "text": [ 117 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 123 | "print(students)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 38, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "6\n", 136 | "我印象最深的同学有6个,他们是:\n", 137 | "Lucy\n", 138 | "Kate\n", 139 | "Jim\n", 140 | "林涛\n", 141 | "李雷\n", 142 | "韩梅梅\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "student_count = len(students)\n", 148 | "print(student_count)\n", 149 | "print('我印象最深的同学有' + str(student_count) + '个,他们是:' )\n", 150 | "for student in students:\n", 151 | " print(student)" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 1, 157 | "metadata": { 158 | "scrolled": true 159 | }, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 166 | "['a', 'b', 'c', 'd']\n", 167 | "['a', 1, 'b', 2, 'c', 3, True, False]\n", 168 | "[[1, 1, 2, 3, 5, 8, 13, 21], ['a', 'b', 'c', 'd'], ['a', 1, 'b', 2, 'c', 3, True, False]]\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "# list内元素支持不同类型的数据;\n", 174 | "# R中的vector要求是同类型的,不可混杂;list则支持不同类型的\n", 175 | "num_str_bool = ['a', 1, 'b', 2, 'c', 3, True, False]\n", 176 | "print(num_str_bool)\n", 177 | "\n", 178 | "# list嵌套\n", 179 | "print([fibonacci_numbers, strings, num_str_bool])" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 20, 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "name": "stdout", 189 | "output_type": "stream", 190 | "text": [ 191 | "[]\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "usernames = []\n", 197 | "print(usernames)" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": {}, 203 | "source": [ 204 | "## 列表解析(列表推导式)\n", 205 | "\n", 206 | "+ 一种优雅的生成列表的方式\n", 207 | "+ 不失可读性\n", 208 | "+ 性能快" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 6, 214 | "metadata": { 215 | "scrolled": true 216 | }, 217 | "outputs": [ 218 | { 219 | "name": "stdout", 220 | "output_type": "stream", 221 | "text": [ 222 | "[1, 1, 2, 3, 5, 8, 13, 21, 999]\n" 223 | ] 224 | } 225 | ], 226 | "source": [ 227 | "# 给列表后面添加一个值\n", 228 | "fibonacci_numbers.append(999)\n", 229 | "print(fibonacci_numbers)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 10, 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "name": "stdout", 239 | "output_type": "stream", 240 | "text": [ 241 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n" 242 | ] 243 | } 244 | ], 245 | "source": [ 246 | "# 传统写法\n", 247 | "a=[]\n", 248 | "for i in range(101):\n", 249 | " if i%2==0:\n", 250 | " a.append(i)\n", 251 | " \n", 252 | "print(a)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 11, 258 | "metadata": { 259 | "scrolled": true 260 | }, 261 | "outputs": [ 262 | { 263 | "name": "stdout", 264 | "output_type": "stream", 265 | "text": [ 266 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n" 267 | ] 268 | } 269 | ], 270 | "source": [ 271 | "# 列表解析\n", 272 | "a=[x for x in range(101) if x%2==0]\n", 273 | "print(a)" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 2, 279 | "metadata": {}, 280 | "outputs": [ 281 | { 282 | "name": "stdout", 283 | "output_type": "stream", 284 | "text": [ 285 | "t\n", 286 | "['M', 'h', 'i', 'f', 'o', 't']\n" 287 | ] 288 | } 289 | ], 290 | "source": [ 291 | "text=\"My house is full of toys\"\n", 292 | "first_charts=[]\n", 293 | "for word in text.split():\n", 294 | " first_charts.append(word[0])\n", 295 | " \n", 296 | "print(word[0])\n", 297 | "print(first_charts)\n" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 18, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "name": "stdout", 307 | "output_type": "stream", 308 | "text": [ 309 | "['M', 'h', 'i', 'f', 'o', 'f']\n" 310 | ] 311 | } 312 | ], 313 | "source": [ 314 | "# 列表解析\n", 315 | "first_charts=[word[0] for word in text.split()]\n", 316 | "print(first_charts)" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": 4, 322 | "metadata": {}, 323 | "outputs": [ 324 | { 325 | "data": { 326 | "text/plain": [ 327 | "[1, 2, 3, 0, 8]" 328 | ] 329 | }, 330 | "execution_count": 4, 331 | "metadata": {}, 332 | "output_type": "execute_result" 333 | } 334 | ], 335 | "source": [ 336 | "a=['1','2','3','i','8']\n", 337 | "[int(i) if i.isdigit() else 0 for i in a]" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 5, 343 | "metadata": { 344 | "scrolled": true 345 | }, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 352 | "[2, 2, 4, 6, 14, 22]\n" 353 | ] 354 | } 355 | ], 356 | "source": [ 357 | "fibonacci_numbers = [1, 1, 2, 3, 5, 8, 13, 21] #斐波那契数\n", 358 | "print(fibonacci_numbers)\n", 359 | "print([ i + 1 for i in fibonacci_numbers if i % 2 != 0 ])" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "## 常见列表操作\n", 367 | "\n", 368 | "+ 读取一个列表的任意一个项目(item)\n", 369 | "+ 遍历一个列表的每个项目(item)\n", 370 | "+ 改变list中item的值\n", 371 | "+ 在列表中找一个item\n", 372 | "+ 在列表中增加一个item\n", 373 | "+ 对列表进行排序\n" 374 | ] 375 | }, 376 | { 377 | "cell_type": "markdown", 378 | "metadata": {}, 379 | "source": [ 380 | "### 读取一个列表的任意一个项目(item)" 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 2, 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "name": "stdout", 390 | "output_type": "stream", 391 | "text": [ 392 | "韩梅梅\n" 393 | ] 394 | } 395 | ], 396 | "source": [ 397 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 398 | "student = students[0]\n", 399 | "print(student)\n" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 25, 405 | "metadata": {}, 406 | "outputs": [ 407 | { 408 | "name": "stdout", 409 | "output_type": "stream", 410 | "text": [ 411 | "Lucy\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "student = students[-1]\n", 417 | "print(student)" 418 | ] 419 | }, 420 | { 421 | "cell_type": "markdown", 422 | "metadata": {}, 423 | "source": [ 424 | "### 遍历一个列表的每个项目(item)" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": 26, 430 | "metadata": {}, 431 | "outputs": [ 432 | { 433 | "name": "stdout", 434 | "output_type": "stream", 435 | "text": [ 436 | "韩梅梅\n", 437 | "李雷\n", 438 | "林涛\n", 439 | "Jim\n", 440 | "Kate\n", 441 | "Lucy\n" 442 | ] 443 | } 444 | ], 445 | "source": [ 446 | "for student in students:\n", 447 | " print(student)" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": 7, 453 | "metadata": { 454 | "scrolled": true 455 | }, 456 | "outputs": [ 457 | { 458 | "name": "stdout", 459 | "output_type": "stream", 460 | "text": [ 461 | "我想韩梅梅\n", 462 | "我想李雷\n", 463 | "我想林涛\n", 464 | "我想Jim\n", 465 | "我想Kate\n", 466 | "我想Lucy\n", 467 | "我想......\n", 468 | "\n", 469 | "我想你们所有人\n" 470 | ] 471 | } 472 | ], 473 | "source": [ 474 | "for student in students:\n", 475 | " print('我想' + student)\n", 476 | "\n", 477 | "print('我想......\\n')\n", 478 | "print('我想你们所有人')" 479 | ] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": 12, 484 | "metadata": {}, 485 | "outputs": [ 486 | { 487 | "name": "stdout", 488 | "output_type": "stream", 489 | "text": [ 490 | "我想0排的韩梅梅\n", 491 | "我想1排的李雷\n", 492 | "我想2排的林涛\n", 493 | "我想3排的Jim\n", 494 | "我想4排的Kate\n", 495 | "我想5排的Lucy\n" 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "# enumerate函数的使用,跟踪每个item的序号\n", 501 | "for index, student in enumerate(students):\n", 502 | " place = str(index)\n", 503 | " print('我想' + place + '排的' + student)" 504 | ] 505 | }, 506 | { 507 | "cell_type": "markdown", 508 | "metadata": {}, 509 | "source": [ 510 | "### 改变list中item的值" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 14, 516 | "metadata": {}, 517 | "outputs": [ 518 | { 519 | "name": "stdout", 520 | "output_type": "stream", 521 | "text": [ 522 | "['韩梅梅', '李雷', '林涛', 'Jim', '杨洋', 'Lucy']\n" 523 | ] 524 | } 525 | ], 526 | "source": [ 527 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 528 | "students[4] = '杨洋'\n", 529 | "print(students)" 530 | ] 531 | }, 532 | { 533 | "cell_type": "markdown", 534 | "metadata": {}, 535 | "source": [ 536 | "### 在列表中找一个item" 537 | ] 538 | }, 539 | { 540 | "cell_type": "code", 541 | "execution_count": 15, 542 | "metadata": { 543 | "scrolled": true 544 | }, 545 | "outputs": [ 546 | { 547 | "ename": "ValueError", 548 | "evalue": "'杨洋' is not in list", 549 | "output_type": "error", 550 | "traceback": [ 551 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 552 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 553 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mstudents\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'韩梅梅'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'李雷'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'林涛'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'Jim'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'Kate'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'Lucy'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstudents\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'杨洋'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 554 | "\u001b[1;31mValueError\u001b[0m: '杨洋' is not in list" 555 | ] 556 | } 557 | ], 558 | "source": [ 559 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 560 | "print(students.index('杨洋'))" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 16, 566 | "metadata": {}, 567 | "outputs": [ 568 | { 569 | "name": "stdout", 570 | "output_type": "stream", 571 | "text": [ 572 | "False\n" 573 | ] 574 | } 575 | ], 576 | "source": [ 577 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 578 | "print('杨洋' in students)" 579 | ] 580 | }, 581 | { 582 | "cell_type": "markdown", 583 | "metadata": {}, 584 | "source": [ 585 | "### 在列表中增加item\n", 586 | "\n", 587 | "#### 用append增加,不限类型\n", 588 | "#### 用extend增加,只能增加list" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 17, 594 | "metadata": {}, 595 | "outputs": [ 596 | { 597 | "name": "stdout", 598 | "output_type": "stream", 599 | "text": [ 600 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy', '杨洋']\n" 601 | ] 602 | } 603 | ], 604 | "source": [ 605 | "# 后面加\n", 606 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 607 | "students.append('杨洋')\n", 608 | "print(students)" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": 67, 614 | "metadata": {}, 615 | "outputs": [ 616 | { 617 | "name": "stdout", 618 | "output_type": "stream", 619 | "text": [ 620 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy', '陈粒', ['陈粒', '邵夷贝'], '杨洋', '张伟', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花']\n" 621 | ] 622 | } 623 | ], 624 | "source": [ 625 | "# 后面加\n", 626 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 627 | "\n", 628 | "\n", 629 | "# append\n", 630 | "students.append('陈粒')\n", 631 | "students.append(['陈粒','邵夷贝'])\n", 632 | "\n", 633 | "# extend\n", 634 | "students.extend(['杨洋','张伟'])\n", 635 | "students.extend('Taylor')\n", 636 | "students.extend('花粥')\n", 637 | "students.extend(['谢春花'])\n", 638 | "\n", 639 | "\n", 640 | "print(students)" 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": 61, 646 | "metadata": {}, 647 | "outputs": [ 648 | { 649 | "data": { 650 | "text/plain": [ 651 | "[1, 2, 3, [4, 5, 6]]" 652 | ] 653 | }, 654 | "execution_count": 61, 655 | "metadata": {}, 656 | "output_type": "execute_result" 657 | } 658 | ], 659 | "source": [ 660 | "a=[1,2,3]\n", 661 | "b=[4,5,6]\n", 662 | "a.append(b)\n", 663 | "a" 664 | ] 665 | }, 666 | { 667 | "cell_type": "code", 668 | "execution_count": 62, 669 | "metadata": {}, 670 | "outputs": [ 671 | { 672 | "data": { 673 | "text/plain": [ 674 | "[1, 2, 3, 4, 5, 6]" 675 | ] 676 | }, 677 | "execution_count": 62, 678 | "metadata": {}, 679 | "output_type": "execute_result" 680 | } 681 | ], 682 | "source": [ 683 | "a=[1,2,3]\n", 684 | "a.extend(b)\n", 685 | "a" 686 | ] 687 | }, 688 | { 689 | "cell_type": "code", 690 | "execution_count": 18, 691 | "metadata": {}, 692 | "outputs": [ 693 | { 694 | "name": "stdout", 695 | "output_type": "stream", 696 | "text": [ 697 | "['韩梅梅', '李雷', '杨洋', '林涛', 'Jim', 'Kate', 'Lucy']\n" 698 | ] 699 | } 700 | ], 701 | "source": [ 702 | "# 指定index加\n", 703 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 704 | "students.insert(2,'杨洋')\n", 705 | "print(students)" 706 | ] 707 | }, 708 | { 709 | "cell_type": "markdown", 710 | "metadata": {}, 711 | "source": [ 712 | "### 删去一个item" 713 | ] 714 | }, 715 | { 716 | "cell_type": "code", 717 | "execution_count": 39, 718 | "metadata": {}, 719 | "outputs": [ 720 | { 721 | "name": "stdout", 722 | "output_type": "stream", 723 | "text": [ 724 | "['李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 725 | ] 726 | } 727 | ], 728 | "source": [ 729 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 730 | "del students[0]\n", 731 | "print(students)" 732 | ] 733 | }, 734 | { 735 | "cell_type": "code", 736 | "execution_count": 41, 737 | "metadata": {}, 738 | "outputs": [ 739 | { 740 | "name": "stdout", 741 | "output_type": "stream", 742 | "text": [ 743 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Lucy']\n" 744 | ] 745 | } 746 | ], 747 | "source": [ 748 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 749 | "students.remove('Kate')\n", 750 | "print(students)" 751 | ] 752 | }, 753 | { 754 | "cell_type": "markdown", 755 | "metadata": {}, 756 | "source": [ 757 | "### 对列表的pop\n", 758 | "\n", 759 | "+ 后进的先用\n", 760 | "+ 用一个少一个\n", 761 | "\n", 762 | "![](http://i1.fuimg.com/611786/8e8cd75b9692c8f0.jpg)" 763 | ] 764 | }, 765 | { 766 | "cell_type": "code", 767 | "execution_count": 43, 768 | "metadata": {}, 769 | "outputs": [ 770 | { 771 | "name": "stdout", 772 | "output_type": "stream", 773 | "text": [ 774 | "Lucy\n", 775 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate']\n" 776 | ] 777 | } 778 | ], 779 | "source": [ 780 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 781 | "last_stu = students.pop()\n", 782 | "\n", 783 | "print(last_stu)\n", 784 | "print(students)" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": 44, 790 | "metadata": {}, 791 | "outputs": [ 792 | { 793 | "name": "stdout", 794 | "output_type": "stream", 795 | "text": [ 796 | "韩梅梅\n", 797 | "['李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 798 | ] 799 | } 800 | ], 801 | "source": [ 802 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 803 | "last_stu = students.pop(0)\n", 804 | "\n", 805 | "print(last_stu)\n", 806 | "print(students)" 807 | ] 808 | }, 809 | { 810 | "cell_type": "markdown", 811 | "metadata": {}, 812 | "source": [ 813 | "### 对列表进行排序\n", 814 | "\n", 815 | "sort和sorted的区别:\n", 816 | "+ 如果用sort对一个列表进行排序,无法再回到原来的顺序。\n", 817 | "+ 如果想排序显示但是又保留原来的顺序,就使用sorted()函数,而且sorted()也支持逆序*reverse=TRUE*。" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": 23, 823 | "metadata": {}, 824 | "outputs": [ 825 | { 826 | "name": "stdout", 827 | "output_type": "stream", 828 | "text": [ 829 | "Jim\n", 830 | "Kate\n", 831 | "Lucy\n", 832 | "李雷\n", 833 | "林涛\n", 834 | "韩梅梅\n", 835 | "['Jim', 'Kate', 'Lucy', '李雷', '林涛', '韩梅梅']\n" 836 | ] 837 | } 838 | ], 839 | "source": [ 840 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 841 | "students.sort()\n", 842 | "for student in students:\n", 843 | " print(student)\n", 844 | " \n", 845 | "print(students)\n", 846 | "\n", 847 | "# python对中文排序比较乱,需要另行处理" 848 | ] 849 | }, 850 | { 851 | "cell_type": "code", 852 | "execution_count": 28, 853 | "metadata": {}, 854 | "outputs": [ 855 | { 856 | "name": "stdout", 857 | "output_type": "stream", 858 | "text": [ 859 | "Jim\n", 860 | "Kate\n", 861 | "Lucy\n", 862 | "李雷\n", 863 | "林涛\n", 864 | "韩梅梅\n", 865 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 866 | ] 867 | } 868 | ], 869 | "source": [ 870 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 871 | "for student in sorted(students, reverse=False):\n", 872 | " print(student)\n", 873 | " \n", 874 | "print(students)\n", 875 | "# 可逆的排序" 876 | ] 877 | }, 878 | { 879 | "cell_type": "code", 880 | "execution_count": 29, 881 | "metadata": {}, 882 | "outputs": [ 883 | { 884 | "name": "stdout", 885 | "output_type": "stream", 886 | "text": [ 887 | "['Lucy', 'Kate', 'Jim', '林涛', '李雷', '韩梅梅']\n" 888 | ] 889 | } 890 | ], 891 | "source": [ 892 | "# 直接反转列表顺序\n", 893 | "\n", 894 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 895 | "students.reverse()\n", 896 | "\n", 897 | "print(students)" 898 | ] 899 | }, 900 | { 901 | "cell_type": "markdown", 902 | "metadata": {}, 903 | "source": [ 904 | "numbers = [1, 3, 4, 2]\n", 905 | "\n", 906 | "* 如何对numbers排序并且不改变原顺序?*" 907 | ] 908 | }, 909 | { 910 | "cell_type": "markdown", 911 | "metadata": { 912 | "slideshow": { 913 | "slide_type": "subslide" 914 | } 915 | }, 916 | "source": [ 917 | "### 索引和切片\n", 918 | "\n", 919 | "Python的索引和切片都是**从0开始**." 920 | ] 921 | }, 922 | { 923 | "cell_type": "code", 924 | "execution_count": 28, 925 | "metadata": { 926 | "scrolled": true 927 | }, 928 | "outputs": [ 929 | { 930 | "name": "stdout", 931 | "output_type": "stream", 932 | "text": [ 933 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 934 | "第1个元素: 1\n", 935 | "第4个元素: 3\n", 936 | "前3个元素: [1, 1, 2]\n", 937 | "第4到最后: [3, 5, 8, 13, 21]\n", 938 | "前3个数: [1, 1, 2]\n" 939 | ] 940 | } 941 | ], 942 | "source": [ 943 | "fibonacci_numbers = [1, 1, 2, 3, 5, 8, 13, 21] \n", 944 | "print(fibonacci_numbers)\n", 945 | "\n", 946 | "# 从0开始\n", 947 | "print('第1个元素:', fibonacci_numbers[0]) # the first element\n", 948 | "print('第4个元素:', fibonacci_numbers[3]) # the fourth element\n", 949 | "\n", 950 | "# 包含左侧,不包含右侧 \n", 951 | "print('前3个元素:', fibonacci_numbers[0:3]) # 前三个元素 [0, 3)\n", 952 | "print('第4到最后:', fibonacci_numbers[3:]) # 第4个到最后\n", 953 | "print('前3个数:', fibonacci_numbers[:3]) # 前3个数" 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": 68, 959 | "metadata": {}, 960 | "outputs": [ 961 | { 962 | "name": "stdout", 963 | "output_type": "stream", 964 | "text": [ 965 | "['林涛', 'Jim', 'Kate']\n" 966 | ] 967 | } 968 | ], 969 | "source": [ 970 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 971 | "f4 = students[2:5]\n", 972 | "print(f4)" 973 | ] 974 | }, 975 | { 976 | "cell_type": "markdown", 977 | "metadata": {}, 978 | "source": [ 979 | "### 复制列表\n", 980 | "+ 注意使用“=”和copy()的区别" 981 | ] 982 | }, 983 | { 984 | "cell_type": "code", 985 | "execution_count": 71, 986 | "metadata": {}, 987 | "outputs": [ 988 | { 989 | "name": "stdout", 990 | "output_type": "stream", 991 | "text": [ 992 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 993 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 994 | "[1, 1, 2, 3, 5, 8, 13, 21, 9999]\n", 995 | "[1, 1, 2, 3, 5, 8, 13, 21, 9999]\n", 996 | "[1, 1, 2, 3, 5, 8, 13, 21]\n" 997 | ] 998 | } 999 | ], 1000 | "source": [ 1001 | "fibonacci_numbers = [1, 1, 2, 3, 5, 8, 13, 21] #斐波那契数\n", 1002 | "aa = fibonacci_numbers\n", 1003 | "print(aa)\n", 1004 | "\n", 1005 | "bb = fibonacci_numbers.copy()\n", 1006 | "print(bb)\n", 1007 | "\n", 1008 | "fibonacci_numbers.append(9999)\n", 1009 | "print(fibonacci_numbers)\n", 1010 | "print(aa) # 等号的话,值会传递\n", 1011 | "print(bb)" 1012 | ] 1013 | }, 1014 | { 1015 | "cell_type": "markdown", 1016 | "metadata": { 1017 | "slideshow": { 1018 | "slide_type": "slide" 1019 | } 1020 | }, 1021 | "source": [ 1022 | "# 元组 \n", 1023 | "+ 元组使用()创立,列表使用[]创立" 1024 | ] 1025 | }, 1026 | { 1027 | "cell_type": "code", 1028 | "execution_count": 76, 1029 | "metadata": {}, 1030 | "outputs": [ 1031 | { 1032 | "name": "stdout", 1033 | "output_type": "stream", 1034 | "text": [ 1035 | "\n", 1036 | "age\n", 1037 | "30\n" 1038 | ] 1039 | } 1040 | ], 1041 | "source": [ 1042 | "# 元组 tuple /taple, tjuple/\n", 1043 | "tuple_example = ('age', 30) # 只读,有序\n", 1044 | "print(type(tuple_example))\n", 1045 | "print(tuple_example[0])\n", 1046 | "print(tuple_example[1])\n", 1047 | "# tuple不能修改元素" 1048 | ] 1049 | }, 1050 | { 1051 | "cell_type": "code", 1052 | "execution_count": 77, 1053 | "metadata": {}, 1054 | "outputs": [ 1055 | { 1056 | "name": "stdout", 1057 | "output_type": "stream", 1058 | "text": [ 1059 | "The first color is: red\n", 1060 | "\n", 1061 | "The available colors are:\n", 1062 | "- red\n", 1063 | "- green\n", 1064 | "- blue\n" 1065 | ] 1066 | } 1067 | ], 1068 | "source": [ 1069 | "colors = ('red', 'green', 'blue')\n", 1070 | "print(\"The first color is: \" + colors[0])\n", 1071 | "\n", 1072 | "print(\"\\nThe available colors are:\")\n", 1073 | "for color in colors:\n", 1074 | " print(\"- \" + color)" 1075 | ] 1076 | }, 1077 | { 1078 | "cell_type": "code", 1079 | "execution_count": 78, 1080 | "metadata": {}, 1081 | "outputs": [ 1082 | { 1083 | "ename": "AttributeError", 1084 | "evalue": "'tuple' object has no attribute 'append'", 1085 | "output_type": "error", 1086 | "traceback": [ 1087 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 1088 | "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", 1089 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mcolors\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'red'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'green'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'blue'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcolors\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'purple'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 1090 | "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" 1091 | ] 1092 | } 1093 | ], 1094 | "source": [ 1095 | "colors = ('red', 'green', 'blue')\n", 1096 | "colors.append('purple')" 1097 | ] 1098 | }, 1099 | { 1100 | "cell_type": "code", 1101 | "execution_count": 79, 1102 | "metadata": {}, 1103 | "outputs": [ 1104 | { 1105 | "name": "stdout", 1106 | "output_type": "stream", 1107 | "text": [ 1108 | "('purple', 'green', 'pink')\n" 1109 | ] 1110 | } 1111 | ], 1112 | "source": [ 1113 | "colors = ('purple', 'green', 'pink')\n", 1114 | "print(colors)" 1115 | ] 1116 | } 1117 | ], 1118 | "metadata": { 1119 | "celltoolbar": "Slideshow", 1120 | "kernelspec": { 1121 | "display_name": "Python 3", 1122 | "language": "python", 1123 | "name": "python3" 1124 | }, 1125 | "language_info": { 1126 | "codemirror_mode": { 1127 | "name": "ipython", 1128 | "version": 3 1129 | }, 1130 | "file_extension": ".py", 1131 | "mimetype": "text/x-python", 1132 | "name": "python", 1133 | "nbconvert_exporter": "python", 1134 | "pygments_lexer": "ipython3", 1135 | "version": "3.7.1" 1136 | }, 1137 | "toc": { 1138 | "base_numbering": 1, 1139 | "nav_menu": {}, 1140 | "number_sections": true, 1141 | "sideBar": true, 1142 | "skip_h1_title": false, 1143 | "title_cell": "Table of Contents", 1144 | "title_sidebar": "Contents", 1145 | "toc_cell": false, 1146 | "toc_position": {}, 1147 | "toc_section_display": true, 1148 | "toc_window_display": true 1149 | } 1150 | }, 1151 | "nbformat": 4, 1152 | "nbformat_minor": 1 1153 | } 1154 | -------------------------------------------------------------------------------- /3-dict_set.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 字典" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### 什么是字典?\n", 15 | "+ 字典以一种联系的方式储存信息,字典储存的是键值对(*\"key-value\" pairs)* ,其中任意一条信息至少和另外一条信息相联系。\n" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "dictionary_name = {key_1: value_1, key_2: value_2, key_3: value_3}" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 2, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "dictionary_name = {'key_1': 'value_1',\n", 32 | " 'key_2': 'value_2',\n", 33 | " 'key_3': 'value_3',\n", 34 | " }" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 1, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "\n", 47 | "Word: list\n", 48 | "Meaning: A collection of values that are not connected, but have an order.\n", 49 | "\n", 50 | "Word: dictionary\n", 51 | "Meaning: A collection of key-value pairs.\n", 52 | "\n", 53 | "Word: function\n", 54 | "Meaning: A named set of instructions that defines a set of actions in Python.\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 60 | " 'dictionary': 'A collection of key-value pairs.',\n", 61 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 62 | " }\n", 63 | "\n", 64 | "print(\"\\nWord: %s\" % 'list')\n", 65 | "print(\"Meaning: %s\" % python_words['list'])\n", 66 | " \n", 67 | "print(\"\\nWord: %s\" % 'dictionary')\n", 68 | "print(\"Meaning: %s\" % python_words['dictionary'])\n", 69 | "\n", 70 | "print(\"\\nWord: %s\" % 'function')\n", 71 | "print(\"Meaning: %s\" % python_words['function'])\n", 72 | "\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "+ 字典有自己的循环形式" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "for key_name, value_name in dictionary_name.items():\n", 87 | " print(key_name) # The key is stored in whatever you called the first variable.\n", 88 | " print(value_name) # The value associated with that key is stored in your second variable." 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 2, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "\n", 101 | "Word: list\n", 102 | "Meaning: A collection of values that are not connected, but have an order.\n", 103 | "\n", 104 | "Word: dictionary\n", 105 | "Meaning: A collection of key-value pairs.\n", 106 | "\n", 107 | "Word: function\n", 108 | "Meaning: A named set of instructions that defines a set of actions in Python.\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 114 | " 'dictionary': 'A collection of key-value pairs.',\n", 115 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 116 | " }\n", 117 | "\n", 118 | "for word, meaning in python_words.items():\n", 119 | " print(\"\\nWord: %s\" % word)\n", 120 | " print(\"Meaning: %s\" % meaning)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 3, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "韩梅梅\n", 133 | "李雷\n", 134 | "林涛\n", 135 | "Jim\n", 136 | "Kate\n", 137 | "Lucy\n" 138 | ] 139 | } 140 | ], 141 | "source": [ 142 | "# 比较一下list\n", 143 | "\n", 144 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 145 | "\n", 146 | "for student in students:\n", 147 | " print(student)\n", 148 | "\n" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "+ 字典中的信息的储存不按顺序,也不能按储存的顺序来提取,换言之,没有index。" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 13, 161 | "metadata": {}, 162 | "outputs": [ 163 | { 164 | "ename": "SyntaxError", 165 | "evalue": "invalid syntax (, line 1)", 166 | "output_type": "error", 167 | "traceback": [ 168 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m python_word{0}\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "python_word{0}" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 4, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "我想0排的韩梅梅\n", 186 | "我想1排的李雷\n", 187 | "我想2排的林涛\n", 188 | "我想3排的Jim\n", 189 | "我想4排的Kate\n", 190 | "我想5排的Lucy\n" 191 | ] 192 | }, 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "'韩梅梅'" 197 | ] 198 | }, 199 | "execution_count": 4, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "for index, student in enumerate(students):\n", 206 | " place = str(index)\n", 207 | " print('我想' + place + '排的' + student)\n", 208 | "students[0]" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "**练习** \n", 216 | "现在你准备一个问题,问你身边的三个同学。 \n", 217 | "把这三个同学的姓名或昵称和他们对你问题的回答以dict的形式储存起来。 \n", 218 | "再以循环的形式print出来。 " 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "### 一般的字典操作" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "#### 增加key-value pair" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 2, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "\n", 245 | "Word: list\n", 246 | "Meaning: A collection of values that are not connected, but have an order.\n", 247 | "\n", 248 | "Word: dictionary\n", 249 | "Meaning: A collection of key-value pairs.\n", 250 | "\n", 251 | "Word: function\n", 252 | "Meaning: A named set of instructions that defines a set of actions in Python.\n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "python_words = {}\n", 258 | "\n", 259 | "# Fill the dictionary, pair by pair.\n", 260 | "python_words['list'] ='A collection of values that are not connected, but have an order.'\n", 261 | "python_words['dictionary'] = 'A collection of key-value pairs.'\n", 262 | "python_words['function'] = 'A named set of instructions that defines a set of actions in Python.'\n", 263 | "\n", 264 | "# Print out the items in the dictionary.\n", 265 | "for word, meaning in python_words.items():\n", 266 | " print(\"\\nWord: %s\" % word)\n", 267 | " print(\"Meaning: %s\" % meaning)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "metadata": {}, 273 | "source": [ 274 | "#### 改变key" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 26, 280 | "metadata": { 281 | "collapsed": true 282 | }, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "\n", 289 | "Word: lisst\n", 290 | "Meaning: A collection of values that are not connected, but have an order.\n", 291 | "\n", 292 | "Word: dictionary\n", 293 | "Meaning: A collection of key-value pairs.\n", 294 | "\n", 295 | "Word: function\n", 296 | "Meaning: A named set of instructions that defines a set of actions in Python.\n", 297 | "\n", 298 | "Word: list\n", 299 | "Meaning: A collection of values that are not connected, but have an order.\n", 300 | "\n", 301 | "Word: dictionary\n", 302 | "Meaning: A collection of key-value pairs.\n", 303 | "\n", 304 | "Word: function\n", 305 | "Meaning: A named set of instructions that defines a set of actions in Python.\n", 306 | "\n", 307 | "Word: list\n", 308 | "Meaning: A collection of values that are not connected, but have an order.\n" 309 | ] 310 | } 311 | ], 312 | "source": [ 313 | "python_words = {'lisst': 'A collection of values that are not connected, but have an order.',\n", 314 | " 'dictionary': 'A collection of key-value pairs.',\n", 315 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 316 | " }\n", 317 | "\n", 318 | "# Create a new, correct key, and connect it to the old value.\n", 319 | "# Then delete the old key.\n", 320 | "python_words['list'] = python_words['lisst']\n", 321 | "\n", 322 | "for word, meaning in python_words.items():\n", 323 | " print(\"\\nWord: %s\" % word)\n", 324 | " print(\"Meaning: %s\" % meaning)\n", 325 | "\n", 326 | "del python_words['lisst']\n", 327 | "\n", 328 | "# Print the dictionary, to show that the key has changed.\n", 329 | "for word, meaning in python_words.items():\n", 330 | " print(\"\\nWord: %s\" % word)\n", 331 | " print(\"Meaning: %s\" % meaning)" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": {}, 337 | "source": [ 338 | "#### 改变value" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 3, 344 | "metadata": {}, 345 | "outputs": [ 346 | { 347 | "name": "stdout", 348 | "output_type": "stream", 349 | "text": [ 350 | "dictionary: A collection of key-value pairs.\n", 351 | "\n", 352 | "dictionary: A collection of key-value pairs. Each key can be used to access its corresponding value.\n" 353 | ] 354 | } 355 | ], 356 | "source": [ 357 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 358 | " 'dictionary': 'A collection of key-value pairs.',\n", 359 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 360 | " }\n", 361 | "\n", 362 | "print('dictionary: ' + python_words['dictionary'])\n", 363 | " \n", 364 | "# Clarify one of the meanings.\n", 365 | "python_words['dictionary'] = 'A collection of key-value pairs. Each key can be used to access its corresponding value.'\n", 366 | "\n", 367 | "print('\\ndictionary: ' + python_words['dictionary'])" 368 | ] 369 | }, 370 | { 371 | "cell_type": "markdown", 372 | "metadata": {}, 373 | "source": [ 374 | "#### 删除key-value pair" 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "execution_count": 5, 380 | "metadata": {}, 381 | "outputs": [ 382 | { 383 | "name": "stdout", 384 | "output_type": "stream", 385 | "text": [ 386 | "\n", 387 | "\n", 388 | "These are the Python words I know:\n", 389 | "\n", 390 | "Word: list\n", 391 | "Meaning: A collection of values that are not connected, but have an order.\n", 392 | "\n", 393 | "Word: dictionary\n", 394 | "Meaning: A collection of key-value pairs.\n", 395 | "\n", 396 | "Word: function\n", 397 | "Meaning: A named set of instructions that defines a set of actions in Python.\n", 398 | "\n", 399 | "\n", 400 | "These are the Python words I know:\n", 401 | "\n", 402 | "Word: dictionary\n", 403 | "Meaning: A collection of key-value pairs.\n", 404 | "\n", 405 | "Word: function\n", 406 | "Meaning: A named set of instructions that defines a set of actions in Python.\n" 407 | ] 408 | } 409 | ], 410 | "source": [ 411 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 412 | " 'dictionary': 'A collection of key-value pairs.',\n", 413 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 414 | " }\n", 415 | "\n", 416 | "# Show the current set of words and meanings.\n", 417 | "print(\"\\n\\nThese are the Python words I know:\")\n", 418 | "for word, meaning in python_words.items():\n", 419 | " print(\"\\nWord: %s\" % word)\n", 420 | " print(\"Meaning: %s\" % meaning)\n", 421 | " \n", 422 | "# Remove the word 'list' and its meaning.\n", 423 | "del python_words['list']\n", 424 | "\n", 425 | "# Show the current set of words and meanings.\n", 426 | "print(\"\\n\\nThese are the Python words I know:\")\n", 427 | "for word, meaning in python_words.items():\n", 428 | " print(\"\\nWord: %s\" % word)\n", 429 | " print(\"Meaning: %s\" % meaning)" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 6, 435 | "metadata": {}, 436 | "outputs": [ 437 | { 438 | "name": "stdout", 439 | "output_type": "stream", 440 | "text": [ 441 | "\n", 442 | "\n", 443 | "These are the Python words I know:\n", 444 | "\n", 445 | "list: A collection of values that are not connected, but have an order.\n", 446 | "\n", 447 | "dictionary: A collection of key-value pairs.\n", 448 | "\n", 449 | "function: A named set of instructions that defines a set of actions in Python.\n", 450 | "\n", 451 | "\n", 452 | "These are the Python words I know:\n", 453 | "\n", 454 | "dictionary: A collection of key-value pairs.\n", 455 | "\n", 456 | "function: A named set of instructions that defines a set of actions in Python.\n" 457 | ] 458 | } 459 | ], 460 | "source": [ 461 | "# 和函数结合使用\n", 462 | "def show_words_meanings(python_words):\n", 463 | " # This function takes in a dictionary of python words and meanings,\n", 464 | " # and prints out each word with its meaning.\n", 465 | " print(\"\\n\\nThese are the Python words I know:\")\n", 466 | " for word, meaning in python_words.items():\n", 467 | " print(\"\\n%s: %s\" % (word, meaning))\n", 468 | " \n", 469 | "\n", 470 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 471 | " 'dictionary': 'A collection of key-value pairs.',\n", 472 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 473 | " }\n", 474 | "\n", 475 | "show_words_meanings(python_words)\n", 476 | " \n", 477 | "# Remove the word 'list' and its meaning.\n", 478 | "del python_words['list']\n", 479 | "\n", 480 | "show_words_meanings(python_words)" 481 | ] 482 | }, 483 | { 484 | "cell_type": "markdown", 485 | "metadata": {}, 486 | "source": [ 487 | "**练习**\n", 488 | "\n", 489 | "已知,以下食物每100g的卡路里如下:\n", 490 | "\n", 491 | "小米粥 45\n", 492 | "粗粮馒头 223\n", 493 | "全麦面包 235\n", 494 | "瘦猪肉 143\n", 495 | "鸡翅 194\n", 496 | "培根 181\n", 497 | "火腿肠 212\n", 498 | "\n", 499 | "\n", 500 | "建立一个空的字典,把上述键值对依此添加进去。\n", 501 | "通过循环形式,显示,如“我吃了二两”+“小米粥”,“增加了”+“45”千卡路里。\n" 502 | ] 503 | }, 504 | { 505 | "cell_type": "markdown", 506 | "metadata": {}, 507 | "source": [ 508 | "### 遍历字典" 509 | ] 510 | }, 511 | { 512 | "cell_type": "markdown", 513 | "metadata": {}, 514 | "source": [ 515 | "#### 遍历字典里所有的key-value paris\n", 516 | "+ 以.item()函数把键值对变成了元组构成的列表" 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "execution_count": 27, 522 | "metadata": {}, 523 | "outputs": [ 524 | { 525 | "name": "stdout", 526 | "output_type": "stream", 527 | "text": [ 528 | "\n", 529 | "Key: key_1\n", 530 | "Value: value_1\n", 531 | "\n", 532 | "Key: key_2\n", 533 | "Value: value_2\n", 534 | "\n", 535 | "Key: key_3\n", 536 | "Value: value_3\n" 537 | ] 538 | } 539 | ], 540 | "source": [ 541 | "my_dict = {'key_1': 'value_1',\n", 542 | " 'key_2': 'value_2',\n", 543 | " 'key_3': 'value_3',\n", 544 | " }\n", 545 | "\n", 546 | "for key, value in my_dict.items():\n", 547 | " print('\\nKey: %s' % key)\n", 548 | " print('Value: %s' % value)" 549 | ] 550 | }, 551 | { 552 | "cell_type": "code", 553 | "execution_count": 7, 554 | "metadata": {}, 555 | "outputs": [ 556 | { 557 | "name": "stdout", 558 | "output_type": "stream", 559 | "text": [ 560 | "dict_items([('key_1', 'value_1'), ('key_2', 'value_2'), ('key_3', 'value_3')])\n" 561 | ] 562 | } 563 | ], 564 | "source": [ 565 | "my_dict = {'key_1': 'value_1',\n", 566 | " 'key_2': 'value_2',\n", 567 | " 'key_3': 'value_3',\n", 568 | " }\n", 569 | "\n", 570 | "print(my_dict.items())\n", 571 | "\n", 572 | "# 上例中,遍历了这个元组列表,并且把每个元组的第一个和第二个item显示出来" 573 | ] 574 | }, 575 | { 576 | "cell_type": "markdown", 577 | "metadata": {}, 578 | "source": [ 579 | "#### 遍历字典里所有的key" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 29, 585 | "metadata": {}, 586 | "outputs": [ 587 | { 588 | "name": "stdout", 589 | "output_type": "stream", 590 | "text": [ 591 | "Key: key_1\n", 592 | "Key: key_2\n", 593 | "Key: key_3\n" 594 | ] 595 | } 596 | ], 597 | "source": [ 598 | "my_dict = {'key_1': 'value_1',\n", 599 | " 'key_2': 'value_2',\n", 600 | " 'key_3': 'value_3',\n", 601 | " }\n", 602 | "\n", 603 | "for key in my_dict:\n", 604 | " print('Key: %s' % key)" 605 | ] 606 | }, 607 | { 608 | "cell_type": "code", 609 | "execution_count": 30, 610 | "metadata": {}, 611 | "outputs": [ 612 | { 613 | "name": "stdout", 614 | "output_type": "stream", 615 | "text": [ 616 | "The following Python words have been defined:\n", 617 | "- list\n", 618 | "- dictionary\n", 619 | "- function\n" 620 | ] 621 | } 622 | ], 623 | "source": [ 624 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 625 | " 'dictionary': 'A collection of key-value pairs.',\n", 626 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 627 | " }\n", 628 | "\n", 629 | "# Show the words that are currently in the dictionary.\n", 630 | "print(\"The following Python words have been defined:\")\n", 631 | "for word in python_words:\n", 632 | " print(\"- %s\" % word)" 633 | ] 634 | }, 635 | { 636 | "cell_type": "code", 637 | "execution_count": 2, 638 | "metadata": {}, 639 | "outputs": [ 640 | { 641 | "name": "stdout", 642 | "output_type": "stream", 643 | "text": [ 644 | "The following Python words have been defined:\n", 645 | "- list\n", 646 | "- dictionary\n", 647 | "- function\n", 648 | "\n", 649 | "What word would you like to learn about? list\n", 650 | "\n", 651 | "list: A collection of values that are not connected, but have an order.\n" 652 | ] 653 | } 654 | ], 655 | "source": [ 656 | "###highlight=[12,13,14]\n", 657 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 658 | " 'dictionary': 'A collection of key-value pairs.',\n", 659 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 660 | " }\n", 661 | "\n", 662 | "# Show the words that are currently in the dictionary.\n", 663 | "print(\"The following Python words have been defined:\")\n", 664 | "for word in python_words:\n", 665 | " print(\"- %s\" % word)\n", 666 | " \n", 667 | "# Allow the user to choose a word, and then display the meaning for that word.\n", 668 | "requested_word = input(\"\\nWhat word would you like to learn about? \")\n", 669 | "print(\"\\n%s: %s\" % (requested_word, python_words[requested_word]))" 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "execution_count": null, 675 | "metadata": { 676 | "collapsed": true 677 | }, 678 | "outputs": [], 679 | "source": [ 680 | "**练习**\n", 681 | "\n", 682 | "在上面已经完成练习的基础上,设计一个“你想知道哪种食物的卡路里?”" 683 | ] 684 | }, 685 | { 686 | "cell_type": "markdown", 687 | "metadata": {}, 688 | "source": [ 689 | "#### 遍历字典里所有的value" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": 1, 695 | "metadata": {}, 696 | "outputs": [ 697 | { 698 | "name": "stdout", 699 | "output_type": "stream", 700 | "text": [ 701 | "Value: value_1\n", 702 | "Value: value_2\n", 703 | "Value: value_3\n" 704 | ] 705 | } 706 | ], 707 | "source": [ 708 | "my_dict = {'key_1': 'value_1',\n", 709 | " 'key_2': 'value_2',\n", 710 | " 'key_3': 'value_3',\n", 711 | " }\n", 712 | "\n", 713 | "for value in my_dict.values():\n", 714 | " print('Value: %s' % value)" 715 | ] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": 3, 720 | "metadata": {}, 721 | "outputs": [ 722 | { 723 | "name": "stdout", 724 | "output_type": "stream", 725 | "text": [ 726 | "Meaning: A collection of values that are not connected, but have an order.\n", 727 | "Meaning: A collection of key-value pairs.\n", 728 | "Meaning: A named set of instructions that defines a set of actions in Python.\n" 729 | ] 730 | } 731 | ], 732 | "source": [ 733 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 734 | " 'dictionary': 'A collection of key-value pairs.',\n", 735 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 736 | " }\n", 737 | "\n", 738 | "for meaning in python_words.values():\n", 739 | " print(\"Meaning: %s\" % meaning)" 740 | ] 741 | }, 742 | { 743 | "cell_type": "code", 744 | "execution_count": 8, 745 | "metadata": {}, 746 | "outputs": [ 747 | { 748 | "name": "stdout", 749 | "output_type": "stream", 750 | "text": [ 751 | "\n", 752 | "A collection of values that are not connected, but have an order.\n", 753 | "\n", 754 | "What word do you think this is?\n", 755 | "list dictionary function \n", 756 | "- list\n", 757 | "You got it!\n", 758 | "\n", 759 | "A collection of key-value pairs.\n", 760 | "\n", 761 | "What word do you think this is?\n", 762 | "list dictionary function \n", 763 | "- dictionary\n", 764 | "You got it!\n", 765 | "\n", 766 | "A named set of instructions that defines a set of actions in Python.\n", 767 | "\n", 768 | "What word do you think this is?\n", 769 | "list dictionary function \n", 770 | "- function\n", 771 | "You got it!\n" 772 | ] 773 | } 774 | ], 775 | "source": [ 776 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 777 | " 'dictionary': 'A collection of key-value pairs.',\n", 778 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 779 | " }\n", 780 | "\n", 781 | "def show_words(python_words):\n", 782 | " # A simple function to show the words in the dictionary.\n", 783 | " display_message = \"\"\n", 784 | " for word in python_words.keys():\n", 785 | " display_message += word + ' '\n", 786 | " print(display_message)\n", 787 | "\n", 788 | "# Print each meaning, one at a time, and ask the user\n", 789 | "# what word they think it is.\n", 790 | "for meaning in python_words.values():\n", 791 | " print(\"\\n%s\" % meaning)\n", 792 | "\n", 793 | " # Assume the guess is not correct; keep guessing until correct.\n", 794 | " correct = False\n", 795 | " while not correct:\n", 796 | " \n", 797 | " print(\"\\nWhat word do you think this is?\")\n", 798 | " show_words(python_words)\n", 799 | " guessed_word = input(\"- \") \n", 800 | " \n", 801 | " # The guess is correct if the guessed word's meaning matches the current meaning.\n", 802 | " if python_words[guessed_word] == meaning:\n", 803 | " print(\"You got it!\")\n", 804 | " correct = True\n", 805 | " else:\n", 806 | " print(\"Sorry, that's just not the right word.\")" 807 | ] 808 | }, 809 | { 810 | "cell_type": "markdown", 811 | "metadata": {}, 812 | "source": [ 813 | "**练习** \n", 814 | "\n", 815 | "常见三种运动的消耗热量表: \n", 816 | "慢走 (一小时4公里) 255 卡 \n", 817 | "慢跑 (一小时9公里) 655 卡 \n", 818 | "羽毛球(一小时) 440 卡 \n", 819 | "\n", 820 | "模仿上例做个刷题,直到答对而且答完为止。" 821 | ] 822 | }, 823 | { 824 | "cell_type": "markdown", 825 | "metadata": {}, 826 | "source": [ 827 | "### 嵌套" 828 | ] 829 | }, 830 | { 831 | "cell_type": "markdown", 832 | "metadata": {}, 833 | "source": [ 834 | "+ 字典里的字典" 835 | ] 836 | }, 837 | { 838 | "cell_type": "code", 839 | "execution_count": 15, 840 | "metadata": {}, 841 | "outputs": [ 842 | { 843 | "name": "stdout", 844 | "output_type": "stream", 845 | "text": [ 846 | "\n", 847 | "我知道每100g的牛奶:\n", 848 | "热量: 60千卡\n", 849 | "蛋白质: 6.1g\n", 850 | "脂肪: 3g\n", 851 | "\n", 852 | "我知道每100g的豆腐:\n", 853 | "热量: 82千卡\n", 854 | "蛋白质: 8.1g\n", 855 | "脂肪: 3.7g\n", 856 | "\n", 857 | "我知道每100g的草鱼:\n", 858 | "热量: 112千卡\n", 859 | "蛋白质: 16.6g\n", 860 | "脂肪: 5.2g\n" 861 | ] 862 | } 863 | ], 864 | "source": [ 865 | "foods = {'牛奶': {'热量': '60千卡', '蛋白质': '6.1g', '脂肪':'3g'},\n", 866 | " '豆腐': {'热量': '82千卡', '蛋白质': '8.1g', '脂肪':'3.7g'},\n", 867 | " '草鱼': {'热量': '112千卡', '蛋白质': '16.6g', '脂肪':'5.2g'},\n", 868 | " }\n", 869 | "\n", 870 | "\n", 871 | "for foods_name, foods_information in foods.items():\n", 872 | " print(\"\\n我知道每100g的%s:\" % foods_name.title())\n", 873 | " print(\"热量: \" + foods_information['热量'])\n", 874 | " print(\"蛋白质: \" + foods_information['蛋白质'])\n", 875 | " print(\"脂肪: \" + foods_information['脂肪'])" 876 | ] 877 | }, 878 | { 879 | "cell_type": "markdown", 880 | "metadata": {}, 881 | "source": [ 882 | "## 集合" 883 | ] 884 | }, 885 | { 886 | "cell_type": "markdown", 887 | "metadata": {}, 888 | "source": [ 889 | "+ 比较集合和字典" 890 | ] 891 | }, 892 | { 893 | "cell_type": "code", 894 | "execution_count": 18, 895 | "metadata": {}, 896 | "outputs": [ 897 | { 898 | "name": "stdout", 899 | "output_type": "stream", 900 | "text": [ 901 | "\n", 902 | "\n" 903 | ] 904 | } 905 | ], 906 | "source": [ 907 | "set_example1 = {'age':30}\n", 908 | "set_example2 = {'age', 30} # 无序,可写\n", 909 | "print(type(set_example1))\n", 910 | "print(type(set_example2))" 911 | ] 912 | }, 913 | { 914 | "cell_type": "markdown", 915 | "metadata": {}, 916 | "source": [ 917 | "+ 集合里的元素不能重复" 918 | ] 919 | }, 920 | { 921 | "cell_type": "code", 922 | "execution_count": 16, 923 | "metadata": {}, 924 | "outputs": [ 925 | { 926 | "name": "stdout", 927 | "output_type": "stream", 928 | "text": [ 929 | "[1, 2, 1, 3]\n", 930 | "{1, 2, 3}\n" 931 | ] 932 | }, 933 | { 934 | "data": { 935 | "text/plain": [ 936 | "[1, 2, 3]" 937 | ] 938 | }, 939 | "execution_count": 16, 940 | "metadata": {}, 941 | "output_type": "execute_result" 942 | } 943 | ], 944 | "source": [ 945 | "li = [1,2,1,3] # 列表\n", 946 | "print(li)\n", 947 | "\n", 948 | "se = {1,2,1,3} # 集合\n", 949 | "print(se)\n", 950 | "list(se)" 951 | ] 952 | } 953 | ], 954 | "metadata": { 955 | "kernelspec": { 956 | "display_name": "Python 3", 957 | "language": "python", 958 | "name": "python3" 959 | }, 960 | "language_info": { 961 | "codemirror_mode": { 962 | "name": "ipython", 963 | "version": 3 964 | }, 965 | "file_extension": ".py", 966 | "mimetype": "text/x-python", 967 | "name": "python", 968 | "nbconvert_exporter": "python", 969 | "pygments_lexer": "ipython3", 970 | "version": "3.6.2" 971 | }, 972 | "toc": { 973 | "base_numbering": 1, 974 | "nav_menu": {}, 975 | "number_sections": true, 976 | "sideBar": true, 977 | "skip_h1_title": false, 978 | "title_cell": "Table of Contents", 979 | "title_sidebar": "Contents", 980 | "toc_cell": false, 981 | "toc_position": {}, 982 | "toc_section_display": true, 983 | "toc_window_display": true 984 | } 985 | }, 986 | "nbformat": 4, 987 | "nbformat_minor": 2 988 | } 989 | -------------------------------------------------------------------------------- /5-function_para.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 函数中参数的传递" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### 缺省参数的定义" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 3, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "\n", 27 | "你作业做的太棒了, 萧敬腾!\n", 28 | "我第一次做的时候绝对做不了这么好.\n", 29 | "\n", 30 | "你作业做的太棒了, 张学友!\n", 31 | "我第一次做的时候绝对做不了这么好.\n", 32 | "\n", 33 | "你作业做的太棒了, 刘德华!\n", 34 | "我第一次做的时候绝对做不了这么好.\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "def thank_you(name):\n", 40 | " # This function prints a two-line personalized thank you message.\n", 41 | " print(\"\\n你作业做的太棒了, %s!\" % name)\n", 42 | " print(\"我第一次做的时候绝对做不了这么好.\")\n", 43 | " \n", 44 | "thank_you('萧敬腾')\n", 45 | "thank_you('张学友')\n", 46 | "thank_you('刘德华')" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "ename": "TypeError", 56 | "evalue": "thank_you() missing 1 required positional argument: 'name'", 57 | "output_type": "error", 58 | "traceback": [ 59 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 60 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 61 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mthank_you\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 62 | "\u001b[1;31mTypeError\u001b[0m: thank_you() missing 1 required positional argument: 'name'" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "thank_you()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 4, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "name": "stdout", 77 | "output_type": "stream", 78 | "text": [ 79 | "\n", 80 | "你作业做的太棒了, 萧敬腾!\n", 81 | "我第一次做的时候绝对做不了这么好.\n", 82 | "\n", 83 | "你作业做的太棒了, 张学友!\n", 84 | "我第一次做的时候绝对做不了这么好.\n", 85 | "\n", 86 | "你作业做的太棒了, 刘德华!\n", 87 | "我第一次做的时候绝对做不了这么好.\n", 88 | "\n", 89 | "你作业做的太棒了, 同学!\n", 90 | "我第一次做的时候绝对做不了这么好.\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "def thank_you(name=\"同学\"):\n", 96 | " # This function prints a two-line personalized thank you message.\n", 97 | " print(\"\\n你作业做的太棒了, %s!\" % name)\n", 98 | " print(\"我第一次做的时候绝对做不了这么好.\")\n", 99 | " \n", 100 | "thank_you('萧敬腾')\n", 101 | "thank_you('张学友')\n", 102 | "thank_you('刘德华')\n", 103 | "thank_you()" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "#### 小练习:我最近最喜欢的电影\n", 111 | "写一个类似的函数,至少调用函数三次,至少有一次不包含参数。" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "### 位置参数\n", 119 | "传递两个以上参数" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 6, 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "昵称: elle\n", 132 | "性别: 女\n", 133 | "城市: 武汉\n", 134 | "\n", 135 | "昵称: S.F.Y\n", 136 | "性别: 女\n", 137 | "城市: 密克罗尼西亚\n", 138 | "\n", 139 | "昵称: 猪早早\n", 140 | "性别: 女\n", 141 | "城市: 米兰\n", 142 | "\n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "def describe_person(nicheng, sex, city):\n", 148 | " print(\"昵称: %s\" % nicheng)\n", 149 | " print(\"性别: %s\" % sex)\n", 150 | " print(\"城市: %s\\n\" % city)\n", 151 | "\n", 152 | "describe_person('elle', '女', '武汉')\n", 153 | "describe_person('S.F.Y', '女', '密克罗尼西亚')\n", 154 | "describe_person('猪早早', '女', '米兰')" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 7, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "name": "stdout", 164 | "output_type": "stream", 165 | "text": [ 166 | "昵称: 武汉\n", 167 | "性别: elle\n", 168 | "城市: 女\n", 169 | "\n", 170 | "昵称: 密克罗尼西亚\n", 171 | "性别: S.F.Y\n", 172 | "城市: 女\n", 173 | "\n", 174 | "昵称: 米兰\n", 175 | "性别: 猪早早\n", 176 | "城市: 女\n", 177 | "\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "def describe_person(nicheng, sex, city):\n", 183 | " print(\"昵称: %s\" % nicheng)\n", 184 | " print(\"性别: %s\" % sex)\n", 185 | " print(\"城市: %s\\n\" % city)\n", 186 | "\n", 187 | "describe_person( '武汉','elle', '女')\n", 188 | "describe_person( '密克罗尼西亚','S.F.Y', '女')\n", 189 | "describe_person( '米兰','猪早早', '女')" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "#### 小练习:炸鸡和啤酒最配\n", 197 | "写一个类似的函数显示你认为最搭的两种食物,至少调用函数三次。" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": {}, 203 | "source": [ 204 | "### 关键词参数" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 9, 210 | "metadata": {}, 211 | "outputs": [ 212 | { 213 | "name": "stdout", 214 | "output_type": "stream", 215 | "text": [ 216 | "昵称: elle\n", 217 | "性别: 女\n", 218 | "城市: 武汉\n", 219 | "\n", 220 | "昵称: S.F.Y\n", 221 | "性别: 女\n", 222 | "城市: 密克罗尼西亚\n", 223 | "\n", 224 | "昵称: 猪早早\n", 225 | "性别: 女\n", 226 | "城市: 米兰\n", 227 | "\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "def describe_person(nicheng, sex, city):\n", 233 | " print(\"昵称: %s\" % nicheng)\n", 234 | " print(\"性别: %s\" % sex)\n", 235 | " print(\"城市: %s\\n\" % city)\n", 236 | "\n", 237 | "describe_person(city= '武汉',nicheng='elle',sex= '女')\n", 238 | "describe_person(city= '密克罗尼西亚',nicheng='S.F.Y', sex='女')\n", 239 | "describe_person(city= '米兰',nicheng='猪早早',sex= '女')" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "metadata": {}, 245 | "source": [ 246 | "### 混合位置和关键词参数" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 11, 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "name": "stdout", 256 | "output_type": "stream", 257 | "text": [ 258 | "性别: 女\n", 259 | "城市: 武汉\n", 260 | "来源: 通过群聊添加\n", 261 | "昵称: elle\n", 262 | "签名: 爱是我们把握最终现实的力量\n", 263 | "\n", 264 | "性别: 女\n", 265 | "城市: 密克罗尼西亚\n", 266 | "来源: 通过分享名片添加\n", 267 | "昵称: S.F.Y\n", 268 | "签名: None\n", 269 | "\n", 270 | "性别: 女\n", 271 | "城市: 米兰\n", 272 | "来源: 通过电话号码添加\n", 273 | "昵称: None\n", 274 | "签名: 不服来战\n", 275 | "\n" 276 | ] 277 | } 278 | ], 279 | "source": [ 280 | "def describe_person(sex, city, source, nicheng=None,signature=None): \n", 281 | " print(\"性别: %s\" % sex)\n", 282 | " print(\"城市: %s\" % city)\n", 283 | " print(\"来源: %s\" % source)\n", 284 | " print(\"昵称: %s\" % nicheng)\n", 285 | " print(\"签名: %s\\n\" % signature)\n", 286 | "\n", 287 | "describe_person( '女', '武汉','通过群聊添加',nicheng='elle',signature='爱是我们把握最终现实的力量')\n", 288 | "describe_person( '女', '密克罗尼西亚','通过分享名片添加',nicheng='S.F.Y')\n", 289 | "describe_person( '女', '米兰','通过电话号码添加',signature='不服来战')" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 13, 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "name": "stdout", 299 | "output_type": "stream", 300 | "text": [ 301 | "性别: 女\n", 302 | "城市: 武汉\n", 303 | "来源: 通过群聊添加\n", 304 | "昵称: elle\n", 305 | "签名: 爱是我们把握最终现实的力量\n", 306 | "\n", 307 | "\n", 308 | "性别: 女\n", 309 | "城市: 密克罗尼西亚\n", 310 | "来源: 通过分享名片添加\n", 311 | "昵称: S.F.Y\n", 312 | "\n", 313 | "\n", 314 | "性别: 女\n", 315 | "城市: 米兰\n", 316 | "来源: 通过电话号码添加\n", 317 | "签名: 不服来战\n", 318 | "\n", 319 | "\n" 320 | ] 321 | } 322 | ], 323 | "source": [ 324 | "def describe_person(sex, city, source, nicheng=None,signature=None): \n", 325 | " print(\"性别: %s\" % sex)\n", 326 | " print(\"城市: %s\" % city)\n", 327 | " print(\"来源: %s\" % source)\n", 328 | " if nicheng:\n", 329 | " print(\"昵称: %s\" % nicheng)\n", 330 | " if signature:\n", 331 | " print(\"签名: %s\" % signature)\n", 332 | " print(\"\\n\")\n", 333 | "\n", 334 | "describe_person( '女', '武汉','通过群聊添加',nicheng='elle',signature='爱是我们把握最终现实的力量')\n", 335 | "describe_person( '女', '密克罗尼西亚','通过分享名片添加',nicheng='S.F.Y')\n", 336 | "describe_person( '女', '米兰','通过电话号码添加',signature='不服来战')" 337 | ] 338 | }, 339 | { 340 | "cell_type": "markdown", 341 | "metadata": {}, 342 | "source": [ 343 | "#### 小练习:清点一下你的购物车\n", 344 | "写一个类似的函数显示商品的属性,使用混合参数的方法,至少调用函数三次。" 345 | ] 346 | }, 347 | { 348 | "cell_type": "markdown", 349 | "metadata": {}, 350 | "source": [ 351 | "### 可变参数" 352 | ] 353 | }, 354 | { 355 | "cell_type": "markdown", 356 | "metadata": {}, 357 | "source": [ 358 | "#### 接受任意长度的序列作为参数\n", 359 | "*args" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "+ 把第一个值给了参数一\n", 367 | "+ 把第二个值给了参数二\n", 368 | "+ 把其他的值,作为**元组**,给了参数三" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 14, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "name": "stdout", 378 | "output_type": "stream", 379 | "text": [ 380 | "\n", 381 | "arg_1: 1\n", 382 | "arg_2: 2\n", 383 | "arg_3: ()\n", 384 | "\n", 385 | "arg_1: 1\n", 386 | "arg_2: 2\n", 387 | "arg_3: (3,)\n", 388 | "\n", 389 | "arg_1: 1\n", 390 | "arg_2: 2\n", 391 | "arg_3: (3, 4)\n", 392 | "\n", 393 | "arg_1: 1\n", 394 | "arg_2: 2\n", 395 | "arg_3: (3, 4, 5)\n" 396 | ] 397 | } 398 | ], 399 | "source": [ 400 | "def example_function(arg_1, arg_2, *arg_3):\n", 401 | " # Let's look at the argument values.\n", 402 | " print('\\narg_1:', arg_1)\n", 403 | " print('arg_2:', arg_2)\n", 404 | " print('arg_3:', arg_3)\n", 405 | " \n", 406 | "example_function(1, 2)\n", 407 | "example_function(1, 2, 3)\n", 408 | "example_function(1, 2, 3, 4)\n", 409 | "example_function(1, 2, 3, 4, 5)" 410 | ] 411 | }, 412 | { 413 | "cell_type": "markdown", 414 | "metadata": {}, 415 | "source": [ 416 | "可以循环形式把元组内容逐一显示出来" 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "execution_count": 15, 422 | "metadata": {}, 423 | "outputs": [ 424 | { 425 | "name": "stdout", 426 | "output_type": "stream", 427 | "text": [ 428 | "\n", 429 | "arg_1: 1\n", 430 | "arg_2: 2\n", 431 | "\n", 432 | "arg_1: 1\n", 433 | "arg_2: 2\n", 434 | "arg_3 value: 3\n", 435 | "\n", 436 | "arg_1: 1\n", 437 | "arg_2: 2\n", 438 | "arg_3 value: 3\n", 439 | "arg_3 value: 4\n", 440 | "\n", 441 | "arg_1: 1\n", 442 | "arg_2: 2\n", 443 | "arg_3 value: 3\n", 444 | "arg_3 value: 4\n", 445 | "arg_3 value: 5\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "def example_function(arg_1, arg_2, *arg_3):\n", 451 | " # Let's look at the argument values.\n", 452 | " print('\\narg_1:', arg_1)\n", 453 | " print('arg_2:', arg_2)\n", 454 | " for value in arg_3:\n", 455 | " print('arg_3 value:', value)\n", 456 | "\n", 457 | "example_function(1, 2)\n", 458 | "example_function(1, 2, 3)\n", 459 | "example_function(1, 2, 3, 4)\n", 460 | "example_function(1, 2, 3, 4, 5)" 461 | ] 462 | }, 463 | { 464 | "cell_type": "markdown", 465 | "metadata": {}, 466 | "source": [ 467 | "#### 小练习:任意长度的数字相加\n", 468 | "在上例的基础上,写一个函数jiafa,可以加两个数,也可以加多个数,并且把和打印出来。" 469 | ] 470 | }, 471 | { 472 | "cell_type": "markdown", 473 | "metadata": {}, 474 | "source": [ 475 | "#### 任意数字作为关键词参数\n", 476 | "**kwargs" 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": {}, 482 | "source": [ 483 | "+ 把第一个值给了参数一\n", 484 | "+ 把第二个值给了参数二\n", 485 | "+ 把其他的值,作为**字典**,给了参数三" 486 | ] 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": 16, 491 | "metadata": {}, 492 | "outputs": [ 493 | { 494 | "name": "stdout", 495 | "output_type": "stream", 496 | "text": [ 497 | "\n", 498 | "arg_1: a\n", 499 | "arg_2: b\n", 500 | "arg_3: {}\n", 501 | "\n", 502 | "arg_1: a\n", 503 | "arg_2: b\n", 504 | "arg_3: {'value_3': 'c'}\n", 505 | "\n", 506 | "arg_1: a\n", 507 | "arg_2: b\n", 508 | "arg_3: {'value_3': 'c', 'value_4': 'd'}\n", 509 | "\n", 510 | "arg_1: a\n", 511 | "arg_2: b\n", 512 | "arg_3: {'value_3': 'c', 'value_4': 'd', 'value_5': 'e'}\n" 513 | ] 514 | } 515 | ], 516 | "source": [ 517 | "def example_function(arg_1, arg_2, **kwargs):\n", 518 | " # Let's look at the argument values.\n", 519 | " print('\\narg_1:', arg_1)\n", 520 | " print('arg_2:', arg_2)\n", 521 | " print('arg_3:', kwargs)\n", 522 | " \n", 523 | "example_function('a', 'b')\n", 524 | "example_function('a', 'b', value_3='c')\n", 525 | "example_function('a', 'b', value_3='c', value_4='d')\n", 526 | "example_function('a', 'b', value_3='c', value_4='d', value_5='e')" 527 | ] 528 | }, 529 | { 530 | "cell_type": "markdown", 531 | "metadata": {}, 532 | "source": [ 533 | "我们也可以通过循环的形式把kwargs里的内容逐一打印出来" 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": 17, 539 | "metadata": {}, 540 | "outputs": [ 541 | { 542 | "name": "stdout", 543 | "output_type": "stream", 544 | "text": [ 545 | "\n", 546 | "arg_1: a\n", 547 | "arg_2: b\n", 548 | "\n", 549 | "arg_1: a\n", 550 | "arg_2: b\n", 551 | "arg_3 value: c\n", 552 | "\n", 553 | "arg_1: a\n", 554 | "arg_2: b\n", 555 | "arg_3 value: c\n", 556 | "arg_3 value: d\n", 557 | "\n", 558 | "arg_1: a\n", 559 | "arg_2: b\n", 560 | "arg_3 value: c\n", 561 | "arg_3 value: d\n", 562 | "arg_3 value: e\n" 563 | ] 564 | } 565 | ], 566 | "source": [ 567 | "def example_function(arg_1, arg_2, **kwargs):\n", 568 | " # Let's look at the argument values.\n", 569 | " print('\\narg_1:', arg_1)\n", 570 | " print('arg_2:', arg_2)\n", 571 | " for key, value in kwargs.items():\n", 572 | " print('arg_3 value:', value)\n", 573 | " \n", 574 | "example_function('a', 'b')\n", 575 | "example_function('a', 'b', value_3='c')\n", 576 | "example_function('a', 'b', value_3='c', value_4='d')\n", 577 | "example_function('a', 'b', value_3='c', value_4='d', value_5='e')" 578 | ] 579 | }, 580 | { 581 | "cell_type": "markdown", 582 | "metadata": {}, 583 | "source": [ 584 | "我们可以把混合位置和关键词参数的方法用kwargs重写一次" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": 19, 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "name": "stdout", 594 | "output_type": "stream", 595 | "text": [ 596 | "性别: 女\n", 597 | "城市: 武汉\n", 598 | "来源: 通过群聊添加\n", 599 | "Nicheng: elle\n", 600 | "Signature: 爱是我们把握最终现实的力量\n", 601 | "\n", 602 | "\n", 603 | "性别: 女\n", 604 | "城市: 密克罗尼西亚\n", 605 | "来源: 通过分享名片添加\n", 606 | "Nicheng: S.F.Y\n", 607 | "\n", 608 | "\n", 609 | "性别: 女\n", 610 | "城市: 米兰\n", 611 | "来源: 通过电话号码添加\n", 612 | "Signature: 不服来战\n", 613 | "\n", 614 | "\n" 615 | ] 616 | } 617 | ], 618 | "source": [ 619 | "def describe_person(sex, city, source, **kwargs): \n", 620 | " print(\"性别: %s\" % sex)\n", 621 | " print(\"城市: %s\" % city)\n", 622 | " print(\"来源: %s\" % source)\n", 623 | " for key in kwargs:\n", 624 | " print(\"%s: %s\" % (key.title(), kwargs[key]))\n", 625 | " print(\"\\n\")\n", 626 | "\n", 627 | "describe_person( '女', '武汉','通过群聊添加',nicheng='elle',signature='爱是我们把握最终现实的力量')\n", 628 | "describe_person( '女', '密克罗尼西亚','通过分享名片添加',nicheng='S.F.Y')\n", 629 | "describe_person( '女', '米兰','通过电话号码添加',signature='不服来战')" 630 | ] 631 | }, 632 | { 633 | "cell_type": "markdown", 634 | "metadata": {}, 635 | "source": [ 636 | "#### 小练习:清点一下你的购物车\n", 637 | "把刚才用混合方法写的清点购物车用kwargs再写一次。" 638 | ] 639 | }, 640 | { 641 | "cell_type": "code", 642 | "execution_count": null, 643 | "metadata": {}, 644 | "outputs": [], 645 | "source": [] 646 | }, 647 | { 648 | "cell_type": "code", 649 | "execution_count": null, 650 | "metadata": {}, 651 | "outputs": [], 652 | "source": [] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": null, 657 | "metadata": {}, 658 | "outputs": [], 659 | "source": [] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": null, 664 | "metadata": {}, 665 | "outputs": [], 666 | "source": [] 667 | }, 668 | { 669 | "cell_type": "code", 670 | "execution_count": null, 671 | "metadata": {}, 672 | "outputs": [], 673 | "source": [] 674 | }, 675 | { 676 | "cell_type": "code", 677 | "execution_count": null, 678 | "metadata": {}, 679 | "outputs": [], 680 | "source": [] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": null, 685 | "metadata": {}, 686 | "outputs": [], 687 | "source": [] 688 | }, 689 | { 690 | "cell_type": "code", 691 | "execution_count": null, 692 | "metadata": {}, 693 | "outputs": [], 694 | "source": [] 695 | }, 696 | { 697 | "cell_type": "code", 698 | "execution_count": null, 699 | "metadata": {}, 700 | "outputs": [], 701 | "source": [] 702 | }, 703 | { 704 | "cell_type": "code", 705 | "execution_count": null, 706 | "metadata": {}, 707 | "outputs": [], 708 | "source": [] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": null, 713 | "metadata": {}, 714 | "outputs": [], 715 | "source": [] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": null, 720 | "metadata": {}, 721 | "outputs": [], 722 | "source": [] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": null, 727 | "metadata": {}, 728 | "outputs": [], 729 | "source": [] 730 | }, 731 | { 732 | "cell_type": "code", 733 | "execution_count": null, 734 | "metadata": {}, 735 | "outputs": [], 736 | "source": [] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "execution_count": null, 741 | "metadata": {}, 742 | "outputs": [], 743 | "source": [] 744 | } 745 | ], 746 | "metadata": { 747 | "kernelspec": { 748 | "display_name": "Python 3", 749 | "language": "python", 750 | "name": "python3" 751 | }, 752 | "language_info": { 753 | "codemirror_mode": { 754 | "name": "ipython", 755 | "version": 3 756 | }, 757 | "file_extension": ".py", 758 | "mimetype": "text/x-python", 759 | "name": "python", 760 | "nbconvert_exporter": "python", 761 | "pygments_lexer": "ipython3", 762 | "version": "3.6.6" 763 | } 764 | }, 765 | "nbformat": 4, 766 | "nbformat_minor": 2 767 | } 768 | -------------------------------------------------------------------------------- /6-class.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## python中的类" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### 类是什么\n", 15 | "介绍类之前,先介绍一个类的实例" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "![](http://i4.fuimg.com/611786/60bdfadccfc93ac5.jpg)" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "对马里奥来说,我们可以描述他的诸多特征:\n", 30 | "+ 大鼻子\n", 31 | "+ 红帽子\n", 32 | "+ 蓝色背带裤\n", 33 | "+ 红色衬衣\n", 34 | "+ 还留着胡子\n" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "![](http://i4.fuimg.com/611786/c4071b1e8f23165e.jpg)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "对马里奥来说,不仅仅是一个静止的形象,还是一个活蹦乱跳的游戏人物:\n", 49 | "+ 跑\n", 50 | "+ 跳、三级跳、远跳\n", 51 | "+ 下蹲\n", 52 | "+ 翻滚\n", 53 | "+ 空中小幅移动\n", 54 | "+ 后空翻、侧空翻\n", 55 | "+ 扔帽子\n", 56 | "+ 游泳\n", 57 | "+ ......" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "![](http://i4.fuimg.com/611786/366e2653983d3b15.jpg)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "![](http://i4.fuimg.com/611786/cda28515c3520f92.gif)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "![](http://i4.fuimg.com/611786/9afa2e58b62149a0.gif)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "![](http://i2.tiimg.com/611786/61a74b5b1117cf31.gif)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "### 总结下,马里奥:\n", 93 | "+ 有一些特征\n", 94 | "+ 有一些“预装”好的操作,或者叫“主角光环”、“人设”等等\n", 95 | "+ “血”掉光了后,重新来过,又有一个新的马里奥\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "### 在python的类里,称之为:\n", 103 | "\n", 104 | "+ 属性(其实就是变量)\n", 105 | "+ 方法(很像函数)\n", 106 | "+ 类和实例" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "### 类的概念概括性很强:\n", 114 | "+ 贫困\n", 115 | " + 阿马蒂亚.森:“可行能力”的贫困\n", 116 | " + 收入是不是贫困的特征呢?\n", 117 | " + 贫困的特征应该是指向获取美好生活的行动的\n", 118 | "+ 依恋类型\n", 119 | " + 一种人格分类\n", 120 | " + 不同的类都有自己的特征和基本稳定的一些恋爱过程中表现(方法、操作等)\n", 121 | " + 你遇到的每个人都是类里的一些实例" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### 类里设定属性的值" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "#### 例子:依恋类型里的倾注型" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 2, 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "class preoccupied():\n", 145 | " def __init__(self):\n", 146 | " self.zhui = True\n", 147 | " self.fenshou = False\n", 148 | " self.manyi = False\n", 149 | " self.jiji = False" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 5, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stdout", 159 | "output_type": "stream", 160 | "text": [ 161 | "\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "boyfriend = preoccupied\n", 167 | "print(boyfriend)" 168 | ] 169 | }, 170 | { 171 | "attachments": {}, 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "#### 倾注型的特点:\n", 176 | "+ “宁可错杀一千也不放过一个”\n", 177 | "+ 天天吵闹要分手,却迟迟不走\n", 178 | "+ 无论你做什么,都对你不满意,嫌你对TA不好\n", 179 | "+ 甚少做出有利于关心的行为" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "#### 《冰雨》\n", 187 | " \n", 188 | "我是在等待一个女孩 \n", 189 | "还是在等待沉沦苦海 \n", 190 | "一段情默默灌溉 \n", 191 | "没有人去管花谢花开 \n", 192 | "无法肯定的爱 左右摇摆 \n", 193 | "只好把心酸往深心里塞 \n", 194 | "...... " 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 73, 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [ 203 | "class preoccupied():\n", 204 | " def __init__(self):\n", 205 | " self.zhui = True\n", 206 | " self.fenshou = False\n", 207 | " self.manyi = False\n", 208 | " self.jiji = False" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 74, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "True\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "mounan = preoccupied()\n", 226 | "print(mounan.zhui)" 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "metadata": {}, 232 | "source": [ 233 | "#### 传递参数" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": null, 239 | "metadata": {}, 240 | "outputs": [], 241 | "source": [ 242 | "class preoccupied():\n", 243 | " def __init__(self):\n", 244 | " self.zhui = True\n", 245 | " self.fenshou = False\n", 246 | " self.manyi = False\n", 247 | " self.jiji = False\n", 248 | " \n", 249 | " def xiangqin(self,girl):\n", 250 | " if girl == 'beautiful' :\n", 251 | " self.zhui = self.zhui\n", 252 | " else :\n", 253 | " self.zhui = self.zhui or True \n", 254 | " \n", 255 | " def chaojia(self,chengdu,cishu):\n", 256 | " if chengdu > 5 or cishu>1000:\n", 257 | " self.fenshou = True\n", 258 | " else :\n", 259 | " self.fenshou = self.fenshou " 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 35, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "name": "stdout", 269 | "output_type": "stream", 270 | "text": [ 271 | "True\n", 272 | "True\n", 273 | "False\n", 274 | "True\n" 275 | ] 276 | } 277 | ], 278 | "source": [ 279 | "mounan = preoccupied()\n", 280 | "print(mounan.zhui)\n", 281 | "\n", 282 | "#### 抓住机会\n", 283 | "mounan.xiangqin(girl = \"ugly\")\n", 284 | "print(mounan.zhui)\n", 285 | "\n", 286 | "#### 一般的吵架不分手\n", 287 | "mounan.chaojia(chengdu = 4,cishu = 20)\n", 288 | "print(mounan.fenshou)\n", 289 | "\n", 290 | "#### 超的少了不分手\n", 291 | "mounan.chaojia(chengdu = 3,cishu = 1001)\n", 292 | "print(mounan.fenshou)\n" 293 | ] 294 | }, 295 | { 296 | "cell_type": "markdown", 297 | "metadata": {}, 298 | "source": [ 299 | "### 类里不设定,生成实例时赋予属性值" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "metadata": {}, 305 | "source": [ 306 | "#### 上例再一般化一些,我们认为可以从追、分手、满意、积极这几个方面来看人在恋爱中表现的话。\n", 307 | "+ 不预先赋值\n", 308 | "+ 生成实例的时候再赋值\n", 309 | "+ 方法保持不变" 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": 65, 315 | "metadata": {}, 316 | "outputs": [], 317 | "source": [ 318 | "class preoccupied(object):\n", 319 | " def __init__(self,x1,x2,x3,x4): ## 需要定义传递的值\n", 320 | " self.zhui = x1\n", 321 | " self.fenshou = x2\n", 322 | " self.manyi = x3\n", 323 | " self.jiji = x4\n", 324 | " \n", 325 | " def xiangqin(self,girl):\n", 326 | " if girl == 'beautiful' :\n", 327 | " self.zhui = self.zhui\n", 328 | " else :\n", 329 | " self.zhui = self.zhui or True \n", 330 | " \n", 331 | " def chaojia(self,chengdu,cishu):\n", 332 | " if chengdu > 5 or cishu>1000:\n", 333 | " self.fenshou = True\n", 334 | " else :\n", 335 | " self.fenshou = self.fenshou " 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 78, 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "name": "stdout", 345 | "output_type": "stream", 346 | "text": [ 347 | "True\n", 348 | "False\n", 349 | "True\n" 350 | ] 351 | } 352 | ], 353 | "source": [ 354 | "mounan = preoccupied(True, False, False, False)\n", 355 | "\n", 356 | "#### 抓住机会\n", 357 | "mounan.xiangqin(girl = \"ugly\")\n", 358 | "print(mounan.zhui)\n", 359 | "\n", 360 | "#### 一般的吵架不分手\n", 361 | "mounan.chaojia(chengdu = 4,cishu = 20)\n", 362 | "print(mounan.fenshou)\n", 363 | "\n", 364 | "#### 超的少了不分手\n", 365 | "mounan.chaojia(chengdu = 3,cishu = 1001)\n", 366 | "print(mounan.fenshou)\n" 367 | ] 368 | }, 369 | { 370 | "cell_type": "markdown", 371 | "metadata": {}, 372 | "source": [ 373 | "#### 创建多个实例" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 82, 379 | "metadata": {}, 380 | "outputs": [ 381 | { 382 | "name": "stdout", 383 | "output_type": "stream", 384 | "text": [ 385 | "True\n", 386 | "True\n", 387 | "True\n" 388 | ] 389 | } 390 | ], 391 | "source": [ 392 | "class preoccupied(object):\n", 393 | " def __init__(self,x1,x2,x3,x4): ## 需要定义传递的值\n", 394 | " self.zhui = x1\n", 395 | " self.fenshou = x2\n", 396 | " self.manyi = x3\n", 397 | " self.jiji = x4\n", 398 | " \n", 399 | " def xiangqin(self,girl):\n", 400 | " if girl == 'beautiful' :\n", 401 | " self.zhui = self.zhui\n", 402 | " else :\n", 403 | " self.zhui = self.zhui or True \n", 404 | " \n", 405 | " def chaojia(self,chengdu,cishu):\n", 406 | " if chengdu > 5 or cishu>1000:\n", 407 | " self.fenshou = True\n", 408 | " else :\n", 409 | " self.fenshou = self.fenshou \n", 410 | "\n", 411 | "yixieren = []\n", 412 | "\n", 413 | "yixieren.append(preoccupied(False, False, False, False))\n", 414 | "yixieren.append(preoccupied(True, False, False, False))\n", 415 | "yixieren.append(preoccupied(True, False, False, True))\n", 416 | "\n", 417 | "for index, man in enumerate(yixieren):\n", 418 | " print(mounan.fenshou)" 419 | ] 420 | }, 421 | { 422 | "cell_type": "markdown", 423 | "metadata": {}, 424 | "source": [ 425 | "#### 改变方法" 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 67, 431 | "metadata": {}, 432 | "outputs": [], 433 | "source": [ 434 | "class preoccupied(object):\n", 435 | " def __init__(self,x1,x2,x3,x4): ## 需要定义传递的值\n", 436 | " self.zhui = x1\n", 437 | " self.fenshou = x2\n", 438 | " self.manyi = x3\n", 439 | " self.jiji = x4\n", 440 | " \n", 441 | " def xiangqin(self,girl):\n", 442 | " if girl == 'beautiful' : # 好看才追\n", 443 | " self.zhui = True\n", 444 | " else :\n", 445 | " self.zhui = self.zhui # 不好看取决于我的人格特质\n", 446 | " \n", 447 | " def chaojia(self,chengdu,cishu):\n", 448 | " if chengdu > 5 or cishu>1000:\n", 449 | " self.fenshou = True\n", 450 | " else :\n", 451 | " self.fenshou = self.fenshou " 452 | ] 453 | }, 454 | { 455 | "cell_type": "code", 456 | "execution_count": 69, 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "False\n" 464 | ] 465 | } 466 | ], 467 | "source": [ 468 | "mounan = preoccupied(False, False, False, False)\n", 469 | "\n", 470 | "#### 抓住机会\n", 471 | "mounan.xiangqin(girl = \"ugly\")\n", 472 | "print(mounan.zhui)\n", 473 | "\n", 474 | "#### 一般的吵架不分手\n", 475 | "mounan.chaojia(chengdu = 4,cishu = 20)\n", 476 | "print(mounan.fenshou)\n", 477 | "\n", 478 | "#### 超的少了不分手\n", 479 | "mounan.chaojia(chengdu = 3,cishu = 1001)\n", 480 | "print(mounan.fenshou)" 481 | ] 482 | }, 483 | { 484 | "cell_type": "markdown", 485 | "metadata": {}, 486 | "source": [ 487 | "#### 练习:学生信息\n", 488 | "+ 创建一个类,包含姓名、分数、睡眠时间三个属性\n", 489 | "+ 包含一个胖瘦的预测,如果分数>90,且睡眠时间少于6小时,输出“BMI可能偏大”,否则输出“体重正常”\n", 490 | "+ 为使得标准(90分、6小时)可以调整,应设为输入的参数" 491 | ] 492 | }, 493 | { 494 | "cell_type": "code", 495 | "execution_count": 59, 496 | "metadata": {}, 497 | "outputs": [], 498 | "source": [ 499 | "class Student(object):\n", 500 | " \n", 501 | " def __init__(self, name, score):\n", 502 | " self.name = name\n", 503 | " self.score = score\n", 504 | " \n", 505 | " def get_grade(self,c1,c2):\n", 506 | " if self.score >= c1:\n", 507 | " return 'A'\n", 508 | " elif self.score >= c2:\n", 509 | " return 'B'\n", 510 | " else:\n", 511 | " return 'C' \n" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": 58, 517 | "metadata": {}, 518 | "outputs": [ 519 | { 520 | "data": { 521 | "text/plain": [ 522 | "'韩梅梅'" 523 | ] 524 | }, 525 | "execution_count": 58, 526 | "metadata": {}, 527 | "output_type": "execute_result" 528 | } 529 | ], 530 | "source": [ 531 | "stu = Student('韩梅梅', 89)\n", 532 | "stu.name\n" 533 | ] 534 | }, 535 | { 536 | "cell_type": "code", 537 | "execution_count": 60, 538 | "metadata": {}, 539 | "outputs": [ 540 | { 541 | "data": { 542 | "text/plain": [ 543 | "'B'" 544 | ] 545 | }, 546 | "execution_count": 60, 547 | "metadata": {}, 548 | "output_type": "execute_result" 549 | } 550 | ], 551 | "source": [ 552 | "stu.get_grade(90,60)" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": null, 558 | "metadata": {}, 559 | "outputs": [], 560 | "source": [] 561 | }, 562 | { 563 | "cell_type": "code", 564 | "execution_count": null, 565 | "metadata": {}, 566 | "outputs": [], 567 | "source": [] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "execution_count": null, 572 | "metadata": {}, 573 | "outputs": [], 574 | "source": [] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": null, 579 | "metadata": {}, 580 | "outputs": [], 581 | "source": [] 582 | }, 583 | { 584 | "cell_type": "markdown", 585 | "metadata": {}, 586 | "source": [ 587 | "### 类的继承" 588 | ] 589 | }, 590 | { 591 | "cell_type": "markdown", 592 | "metadata": {}, 593 | "source": [ 594 | "#### 马里奥的历史很悠久\n", 595 | "+ 有很早期的街机\n", 596 | "+ 红白机\n", 597 | "+ .......\n", 598 | "+ switch\n", 599 | "\n", 600 | "但是他的一些基本特征和操作,一直保留下来,后期的马里奥都继承了之前版本的经典部分" 601 | ] 602 | }, 603 | { 604 | "cell_type": "markdown", 605 | "metadata": {}, 606 | "source": [ 607 | "#### 定义一个火箭" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": 87, 613 | "metadata": {}, 614 | "outputs": [ 615 | { 616 | "name": "stdout", 617 | "output_type": "stream", 618 | "text": [ 619 | "The rockets are 11.180340 units apart.\n" 620 | ] 621 | } 622 | ], 623 | "source": [ 624 | "from math import sqrt\n", 625 | "\n", 626 | "class Rocket():\n", 627 | " # Rocket simulates a rocket ship for a game,\n", 628 | " # or a physics simulation.\n", 629 | " \n", 630 | " def __init__(self, x=0, y=0):\n", 631 | " # Each rocket has an (x,y) position.\n", 632 | " self.x = x\n", 633 | " self.y = y\n", 634 | " \n", 635 | " def move_rocket(self, x_increment=0, y_increment=1):\n", 636 | " # Move the rocket according to the paremeters given.\n", 637 | " # Default behavior is to move the rocket up one unit.\n", 638 | " self.x += x_increment\n", 639 | " self.y += y_increment\n", 640 | " \n", 641 | " def get_distance(self, other_rocket):\n", 642 | " # Calculates the distance from this rocket to another rocket,\n", 643 | " # and returns that value.\n", 644 | " distance = sqrt((self.x-other_rocket.x)**2+(self.y-other_rocket.y)**2)\n", 645 | " return distance\n", 646 | " \n", 647 | "rocket_0 = Rocket()\n", 648 | "rocket_1 = Rocket(10,5)\n", 649 | "\n", 650 | "# Show the distance between them.\n", 651 | "distance = rocket_0.get_distance(rocket_1)\n", 652 | "print(\"The rockets are %f units apart.\" % distance)" 653 | ] 654 | }, 655 | { 656 | "cell_type": "markdown", 657 | "metadata": {}, 658 | "source": [ 659 | "#### 航天飞机继承了火箭" 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "execution_count": 92, 665 | "metadata": {}, 666 | "outputs": [ 667 | { 668 | "name": "stdout", 669 | "output_type": "stream", 670 | "text": [ 671 | "3\n", 672 | "The shuttle are 11.180340 units apart.\n" 673 | ] 674 | } 675 | ], 676 | "source": [ 677 | "class Shuttle(Rocket):\n", 678 | " # Shuttle simulates a space shuttle, which is really\n", 679 | " # just a reusable rocket.\n", 680 | " \n", 681 | " def __init__(self, x=0, y=0, flights_completed=0):\n", 682 | " super().__init__(x, y) ## 通过super函数声明继承了父类的属性\n", 683 | " self.flights_completed = flights_completed\n", 684 | " \n", 685 | "shuttle = Shuttle(10,0,3)\n", 686 | "print(shuttle.flights_completed)\n", 687 | "\n", 688 | "\n", 689 | "\n", 690 | "rocket_0 = Shuttle()\n", 691 | "rocket_1 = Shuttle(10,5,3)\n", 692 | "\n", 693 | "# Show the distance between them.\n", 694 | "distance = rocket_0.get_distance(rocket_1)\n", 695 | "print(\"The shuttle are %f units apart.\" % distance)" 696 | ] 697 | }, 698 | { 699 | "cell_type": "code", 700 | "execution_count": null, 701 | "metadata": {}, 702 | "outputs": [], 703 | "source": [] 704 | } 705 | ], 706 | "metadata": { 707 | "kernelspec": { 708 | "display_name": "Python 3", 709 | "language": "python", 710 | "name": "python3" 711 | }, 712 | "language_info": { 713 | "codemirror_mode": { 714 | "name": "ipython", 715 | "version": 3 716 | }, 717 | "file_extension": ".py", 718 | "mimetype": "text/x-python", 719 | "name": "python", 720 | "nbconvert_exporter": "python", 721 | "pygments_lexer": "ipython3", 722 | "version": "3.6.6" 723 | } 724 | }, 725 | "nbformat": 4, 726 | "nbformat_minor": 2 727 | } 728 | -------------------------------------------------------------------------------- /7-review.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 基础对象\n", 8 | "\n", 9 | "- int: 整数,如1, 2, 3\n", 10 | "\n", 11 | "\n", 12 | "- float: 浮点数,如2.3, 3.6\n", 13 | "\n", 14 | "\n", 15 | "- bool: 布尔,包括True, False\n", 16 | "\n", 17 | "\n", 18 | "- str: 字符串,如'12.3', 'abcd'" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "\n", 31 | "\n", 32 | "\n", 33 | "\n", 34 | "hello\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "print(type(1))\n", 40 | "print(type(1.2))\n", 41 | "print(type(True))\n", 42 | "print(type('123'))\n", 43 | "print(\"hello\")" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## 变量及运算" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "### 字符串变量\n", 58 | "\n", 59 | "#### 常用字符串变量函数\n", 60 | "\n", 61 | "+ print\n", 62 | "+ .title()\n", 63 | "+ .upper()\n", 64 | "+ .lower()\n", 65 | "+ 连接符: +\n", 66 | "+ 换行符:\\n\n", 67 | "+ 空格符:\\\n", 68 | "+ 制表符:\\t\n", 69 | "+ 去空格:.lstrip(), .rstrip(),.strip()\n", 70 | "+ 分词:.split\n", 71 | "+ 判断是否字串形式数字:.isdigit()\n", 72 | "+ 转为整数:int()\n", 73 | "+ 接收用户输入:input()\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "my_string = \"This is a double-quoted string.\"\n", 83 | "print(my_string)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "print('123' + 'HELLO')" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "print(\"Hello everyone!\")\n", 102 | "print(\"Hello \\teveryone!\")\n", 103 | "print(\"\\tHello everyone!\")\n", 104 | "\n", 105 | "print(\"\\nHello everyone!\")\n", 106 | "print(\"Hello \\neveryone!\")\n", 107 | "print(\"Hello \\n\\n\\neveryone!\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "name = ' eric '\n", 117 | "\n", 118 | "print(name.lstrip())\n", 119 | "print(name.rstrip())\n", 120 | "print(name.strip())" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### 数字变量\n", 128 | "\n", 129 | "#### 常用数字变量函数\n", 130 | "\n", 131 | "+ 一般运算:+、-、*、/\n", 132 | "+ 整数除法://\n", 133 | "+ 取余:%" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 4, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "5\n", 146 | "1\n", 147 | "6\n", 148 | "1.5\n", 149 | "9\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "print(3+2)\n", 155 | "print(3-2)\n", 156 | "print(3*2)\n", 157 | "print(3/2)\n", 158 | "print(3**2)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": {}, 164 | "source": [ 165 | "### 字符和数字混排\n", 166 | "\n", 167 | "+ 占位符:%s、%d、%f" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 3, 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "5 / 2 = 2.5\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "print(\"5 / 2 = %s\" %(5 / 2))" 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "metadata": {}, 190 | "source": [ 191 | "### 逻辑判断\n", 192 | "+ 等于(==)\n", 193 | "+ 不等于(!=)\n", 194 | "+ 其他不等号(>,>=,<,<=)\n", 195 | "+ and\n", 196 | "+ or" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 6, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "data": { 206 | "text/plain": [ 207 | "True" 208 | ] 209 | }, 210 | "execution_count": 6, 211 | "metadata": {}, 212 | "output_type": "execute_result" 213 | } 214 | ], 215 | "source": [ 216 | "5 == 5" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 7, 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "data": { 226 | "text/plain": [ 227 | "False" 228 | ] 229 | }, 230 | "execution_count": 7, 231 | "metadata": {}, 232 | "output_type": "execute_result" 233 | } 234 | ], 235 | "source": [ 236 | "3 == 5" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 8, 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "data": { 246 | "text/plain": [ 247 | "False" 248 | ] 249 | }, 250 | "execution_count": 8, 251 | "metadata": {}, 252 | "output_type": "execute_result" 253 | } 254 | ], 255 | "source": [ 256 | "4 < 3 " 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 9, 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "data": { 266 | "text/plain": [ 267 | "False" 268 | ] 269 | }, 270 | "execution_count": 9, 271 | "metadata": {}, 272 | "output_type": "execute_result" 273 | } 274 | ], 275 | "source": [ 276 | "'Eric' == 'eric'" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": 11, 282 | "metadata": {}, 283 | "outputs": [ 284 | { 285 | "name": "stdout", 286 | "output_type": "stream", 287 | "text": [ 288 | "False\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "x = 2\n", 294 | "print (x >= -1 and x>3)" 295 | ] 296 | }, 297 | { 298 | "cell_type": "markdown", 299 | "metadata": {}, 300 | "source": [ 301 | "## 控制流\n", 302 | "\n", 303 | "### 条件控制\n", 304 | "\n", 305 | " if :\n", 306 | " do()\n", 307 | " elif :\n", 308 | " do_other()\n", 309 | " else:\n", 310 | " do_another()" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 1, 316 | "metadata": {}, 317 | "outputs": [ 318 | { 319 | "name": "stdout", 320 | "output_type": "stream", 321 | "text": [ 322 | "a小于等于1\n" 323 | ] 324 | } 325 | ], 326 | "source": [ 327 | "a = 0\n", 328 | "\n", 329 | "if a > 2 :\n", 330 | " print(\"a大于2\")\n", 331 | "elif a > 1 :\n", 332 | " print(\"a小于等于2,大于1\")\n", 333 | "else:\n", 334 | " print(\"a小于等于1\")" 335 | ] 336 | }, 337 | { 338 | "cell_type": "markdown", 339 | "metadata": {}, 340 | "source": [ 341 | "### 循环\n", 342 | "\n", 343 | "#### while\n", 344 | "\n", 345 | "- while 循环\n", 346 | "\n", 347 | "```\n", 348 | " while :\n", 349 | " do()\n", 350 | " update_condition()\n", 351 | "```\n" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 5, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "name": "stdout", 361 | "output_type": "stream", 362 | "text": [ 363 | "2550\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "sum = 0\n", 369 | "i = 0\n", 370 | "\n", 371 | "while i <= 100:\n", 372 | " if i % 2 == 0:\n", 373 | " sum += i \n", 374 | " else:\n", 375 | " pass \n", 376 | " i += 1\n", 377 | "\n", 378 | "print(sum)" 379 | ] 380 | }, 381 | { 382 | "cell_type": "markdown", 383 | "metadata": {}, 384 | "source": [ 385 | "#### for循环\n", 386 | "\n", 387 | "```\n", 388 | " for x in :\n", 389 | " do()\n", 390 | "```" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 9, 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "name": "stdout", 400 | "output_type": "stream", 401 | "text": [ 402 | "Alice, that was a great trick!\n", 403 | "I can't wait to see your next trick, Alice.\n", 404 | "\n", 405 | "Thank you everyone, that was a great magic show!\n", 406 | "David, that was a great trick!\n", 407 | "I can't wait to see your next trick, David.\n", 408 | "\n", 409 | "Thank you everyone, that was a great magic show!\n", 410 | "Carolina, that was a great trick!\n", 411 | "I can't wait to see your next trick, Carolina.\n", 412 | "\n", 413 | "Thank you everyone, that was a great magic show!\n" 414 | ] 415 | } 416 | ], 417 | "source": [ 418 | "magicians = ['alice', 'david', 'carolina'] \n", 419 | "for magician in magicians: \n", 420 | " print(magician.title() + \", that was a great trick!\") \n", 421 | " print(\"I can't wait to see your next trick, \" + magician.title() + \".\\n\") \n", 422 | " \n", 423 | " print(\"Thank you everyone, that was a great magic show!\")" 424 | ] 425 | }, 426 | { 427 | "cell_type": "markdown", 428 | "metadata": {}, 429 | "source": [ 430 | "### 控制异常" 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": null, 436 | "metadata": {}, 437 | "outputs": [], 438 | "source": [ 439 | "try: \n", 440 | " 语句1 \n", 441 | " 语句2 \n", 442 | " . \n", 443 | " . \n", 444 | " 语句N \n", 445 | "except .........: \n", 446 | " do something ....... " 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": null, 452 | "metadata": {}, 453 | "outputs": [], 454 | "source": [ 455 | "def isFloat(string):\n", 456 | " is_float=1\n", 457 | " try:\n", 458 | " float(string)\n", 459 | " except:\n", 460 | " is_float=0\n", 461 | " return is_float\n", 462 | "\n", 463 | "GPA = input(\"请输入你的加权分数,要求精确到小数点后1位 \")\n", 464 | "\n", 465 | "\n", 466 | "while isFloat(GPA) == 0:\n", 467 | " GPA = input(\"请输入阿拉伯数字形式的加权分数,要求精确到小数点后1位 \")\n", 468 | " \n", 469 | "GPA = float(GPA) \n", 470 | "print(type(GPA))\n", 471 | "print(GPA)" 472 | ] 473 | }, 474 | { 475 | "cell_type": "markdown", 476 | "metadata": {}, 477 | "source": [ 478 | "## 数据结构" 479 | ] 480 | }, 481 | { 482 | "cell_type": "markdown", 483 | "metadata": {}, 484 | "source": [ 485 | "### list\n", 486 | "\n", 487 | "+ python使用方括号指明列表,students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 488 | "+ 也可使用list(range(1,6))得到数字list\n", 489 | "+ len()" 490 | ] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": 10, 495 | "metadata": {}, 496 | "outputs": [ 497 | { 498 | "name": "stdout", 499 | "output_type": "stream", 500 | "text": [ 501 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 502 | ] 503 | } 504 | ], 505 | "source": [ 506 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 507 | "print(students)" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": 11, 513 | "metadata": {}, 514 | "outputs": [ 515 | { 516 | "name": "stdout", 517 | "output_type": "stream", 518 | "text": [ 519 | "['a', 1, 'b', 2, 'c', 3, True, False]\n" 520 | ] 521 | } 522 | ], 523 | "source": [ 524 | "num_str_bool = ['a', 1, 'b', 2, 'c', 3, True, False]\n", 525 | "print(num_str_bool)" 526 | ] 527 | }, 528 | { 529 | "cell_type": "markdown", 530 | "metadata": {}, 531 | "source": [ 532 | "#### 列表解析式" 533 | ] 534 | }, 535 | { 536 | "cell_type": "code", 537 | "execution_count": 12, 538 | "metadata": {}, 539 | "outputs": [ 540 | { 541 | "name": "stdout", 542 | "output_type": "stream", 543 | "text": [ 544 | "[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]\n" 545 | ] 546 | } 547 | ], 548 | "source": [ 549 | "a=[x for x in range(101) if x%3==0]\n", 550 | "print(a)" 551 | ] 552 | }, 553 | { 554 | "cell_type": "markdown", 555 | "metadata": {}, 556 | "source": [ 557 | "#### 常见列表操作\n", 558 | "+ 读取一个列表的任意一个项目(item):listname[i]\n", 559 | "+ 读取一个列表中若干个项目(item):listname[i:j]\n", 560 | "+ 遍历一个列表的每个项目(item):for 结构\n", 561 | "+ 改变list中item的值:listname[i] = newvalue\n", 562 | "+ 在列表中找一个item:value in listname\n", 563 | "+ 在列表中增加一个item:listname.append()和list.extend()\n", 564 | "+ 在列表中删除一个item:del listname[i]、listname.remove(item)和listname.pop()\n", 565 | "+ 对列表进行排序:listname.sort()和sorted(listname)\n", 566 | "+ 列表顺序的反转:listname.reverse()\n", 567 | "+ 列表的复制:=和listname.copy()" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 13, 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "name": "stdout", 577 | "output_type": "stream", 578 | "text": [ 579 | "韩梅梅\n" 580 | ] 581 | } 582 | ], 583 | "source": [ 584 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 585 | "student = students[0]\n", 586 | "print(student)" 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": 15, 592 | "metadata": {}, 593 | "outputs": [ 594 | { 595 | "name": "stdout", 596 | "output_type": "stream", 597 | "text": [ 598 | "前3个同学: ['韩梅梅', '李雷', '林涛']\n" 599 | ] 600 | } 601 | ], 602 | "source": [ 603 | "print('前3个同学:', students[0:3])" 604 | ] 605 | }, 606 | { 607 | "cell_type": "code", 608 | "execution_count": 14, 609 | "metadata": {}, 610 | "outputs": [ 611 | { 612 | "name": "stdout", 613 | "output_type": "stream", 614 | "text": [ 615 | "韩梅梅\n", 616 | "李雷\n", 617 | "林涛\n", 618 | "Jim\n", 619 | "Kate\n", 620 | "Lucy\n" 621 | ] 622 | } 623 | ], 624 | "source": [ 625 | "for student in students:\n", 626 | " print(student)" 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "execution_count": 16, 632 | "metadata": {}, 633 | "outputs": [ 634 | { 635 | "name": "stdout", 636 | "output_type": "stream", 637 | "text": [ 638 | "['韩梅梅', '李雷', '林涛', 'Jim', '杨洋', 'Lucy']\n" 639 | ] 640 | } 641 | ], 642 | "source": [ 643 | "students[4] = '杨洋'\n", 644 | "print(students)" 645 | ] 646 | }, 647 | { 648 | "cell_type": "code", 649 | "execution_count": 17, 650 | "metadata": {}, 651 | "outputs": [ 652 | { 653 | "name": "stdout", 654 | "output_type": "stream", 655 | "text": [ 656 | "True\n" 657 | ] 658 | } 659 | ], 660 | "source": [ 661 | "print('杨洋' in students)" 662 | ] 663 | }, 664 | { 665 | "cell_type": "code", 666 | "execution_count": 18, 667 | "metadata": {}, 668 | "outputs": [ 669 | { 670 | "name": "stdout", 671 | "output_type": "stream", 672 | "text": [ 673 | "['韩梅梅', '李雷', '林涛', 'Jim', '杨洋', 'Lucy', '王晨']\n" 674 | ] 675 | } 676 | ], 677 | "source": [ 678 | "students.append('王晨')\n", 679 | "print(students)" 680 | ] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": 21, 685 | "metadata": {}, 686 | "outputs": [ 687 | { 688 | "data": { 689 | "text/plain": [ 690 | "[1, 2, 3, [4, 5, 6]]" 691 | ] 692 | }, 693 | "execution_count": 21, 694 | "metadata": {}, 695 | "output_type": "execute_result" 696 | } 697 | ], 698 | "source": [ 699 | "a=[1,2,3]\n", 700 | "b=[4,5,6]\n", 701 | "a.append(b)\n", 702 | "a" 703 | ] 704 | }, 705 | { 706 | "cell_type": "code", 707 | "execution_count": 22, 708 | "metadata": {}, 709 | "outputs": [ 710 | { 711 | "data": { 712 | "text/plain": [ 713 | "[1, 2, 3, 4, 5, 6]" 714 | ] 715 | }, 716 | "execution_count": 22, 717 | "metadata": {}, 718 | "output_type": "execute_result" 719 | } 720 | ], 721 | "source": [ 722 | "a=[1,2,3]\n", 723 | "a.extend(b)\n", 724 | "a" 725 | ] 726 | }, 727 | { 728 | "cell_type": "code", 729 | "execution_count": 20, 730 | "metadata": {}, 731 | "outputs": [ 732 | { 733 | "name": "stdout", 734 | "output_type": "stream", 735 | "text": [ 736 | "['韩梅梅', '李雷', '林涛', 'Jim', '杨洋', 'Lucy', '王晨', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花']\n" 737 | ] 738 | } 739 | ], 740 | "source": [ 741 | "students.extend(['陈粒','程璧'])\n", 742 | "students.extend('Taylor')\n", 743 | "students.extend('花粥')\n", 744 | "students.extend(['谢春花'])\n", 745 | "print(students)" 746 | ] 747 | }, 748 | { 749 | "cell_type": "code", 750 | "execution_count": 23, 751 | "metadata": {}, 752 | "outputs": [ 753 | { 754 | "name": "stdout", 755 | "output_type": "stream", 756 | "text": [ 757 | "['李雷', '林涛', 'Jim', '杨洋', 'Lucy', '王晨', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花']\n" 758 | ] 759 | } 760 | ], 761 | "source": [ 762 | "del students[0]\n", 763 | "print(students)" 764 | ] 765 | }, 766 | { 767 | "cell_type": "code", 768 | "execution_count": 25, 769 | "metadata": {}, 770 | "outputs": [ 771 | { 772 | "name": "stdout", 773 | "output_type": "stream", 774 | "text": [ 775 | "['李雷', '林涛', '杨洋', 'Lucy', '王晨', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花', '陈粒', '程璧', 'T', 'a', 'y', 'l', 'o', 'r', '花', '粥', '谢春花']\n" 776 | ] 777 | } 778 | ], 779 | "source": [ 780 | "students.remove('Jim')\n", 781 | "print(students)" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": 26, 787 | "metadata": {}, 788 | "outputs": [ 789 | { 790 | "name": "stdout", 791 | "output_type": "stream", 792 | "text": [ 793 | "Lucy\n", 794 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate']\n" 795 | ] 796 | } 797 | ], 798 | "source": [ 799 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 800 | "last_stu = students.pop()\n", 801 | "\n", 802 | "print(last_stu)\n", 803 | "print(students)" 804 | ] 805 | }, 806 | { 807 | "cell_type": "code", 808 | "execution_count": 27, 809 | "metadata": {}, 810 | "outputs": [ 811 | { 812 | "name": "stdout", 813 | "output_type": "stream", 814 | "text": [ 815 | "Jim\n", 816 | "Kate\n", 817 | "Lucy\n", 818 | "李雷\n", 819 | "林涛\n", 820 | "韩梅梅\n", 821 | "['Jim', 'Kate', 'Lucy', '李雷', '林涛', '韩梅梅']\n" 822 | ] 823 | } 824 | ], 825 | "source": [ 826 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 827 | "students.sort()\n", 828 | "for student in students:\n", 829 | " print(student)\n", 830 | " \n", 831 | "print(students)" 832 | ] 833 | }, 834 | { 835 | "cell_type": "code", 836 | "execution_count": 28, 837 | "metadata": {}, 838 | "outputs": [ 839 | { 840 | "name": "stdout", 841 | "output_type": "stream", 842 | "text": [ 843 | "Jim\n", 844 | "Kate\n", 845 | "Lucy\n", 846 | "李雷\n", 847 | "林涛\n", 848 | "韩梅梅\n", 849 | "['韩梅梅', '李雷', '林涛', 'Jim', 'Kate', 'Lucy']\n" 850 | ] 851 | } 852 | ], 853 | "source": [ 854 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 855 | "for student in sorted(students, reverse=False):\n", 856 | " print(student)\n", 857 | " \n", 858 | "print(students)" 859 | ] 860 | }, 861 | { 862 | "cell_type": "code", 863 | "execution_count": 29, 864 | "metadata": {}, 865 | "outputs": [ 866 | { 867 | "name": "stdout", 868 | "output_type": "stream", 869 | "text": [ 870 | "['Lucy', 'Kate', 'Jim', '林涛', '李雷', '韩梅梅']\n" 871 | ] 872 | } 873 | ], 874 | "source": [ 875 | "students = ['韩梅梅', '李雷', '林涛','Jim','Kate','Lucy']\n", 876 | "students.reverse()\n", 877 | "\n", 878 | "print(students)" 879 | ] 880 | }, 881 | { 882 | "cell_type": "code", 883 | "execution_count": 30, 884 | "metadata": {}, 885 | "outputs": [ 886 | { 887 | "name": "stdout", 888 | "output_type": "stream", 889 | "text": [ 890 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 891 | "[1, 1, 2, 3, 5, 8, 13, 21]\n", 892 | "[1, 1, 2, 3, 5, 8, 13, 21, 9999]\n", 893 | "[1, 1, 2, 3, 5, 8, 13, 21, 9999]\n", 894 | "[1, 1, 2, 3, 5, 8, 13, 21]\n" 895 | ] 896 | } 897 | ], 898 | "source": [ 899 | "fibonacci_numbers = [1, 1, 2, 3, 5, 8, 13, 21] #斐波那契数\n", 900 | "aa = fibonacci_numbers\n", 901 | "print(aa)\n", 902 | "\n", 903 | "bb = fibonacci_numbers.copy()\n", 904 | "print(bb)\n", 905 | "\n", 906 | "fibonacci_numbers.append(9999)\n", 907 | "print(fibonacci_numbers)\n", 908 | "print(aa) # 等号的话,值会传递\n", 909 | "print(bb)" 910 | ] 911 | }, 912 | { 913 | "cell_type": "markdown", 914 | "metadata": {}, 915 | "source": [ 916 | "### 元组\n", 917 | "\n", 918 | "+ 元组使用()创立,列表使用[]创立\n", 919 | "+ 元组不能修改item" 920 | ] 921 | }, 922 | { 923 | "cell_type": "code", 924 | "execution_count": 31, 925 | "metadata": {}, 926 | "outputs": [ 927 | { 928 | "name": "stdout", 929 | "output_type": "stream", 930 | "text": [ 931 | "\n", 932 | "age\n", 933 | "30\n" 934 | ] 935 | } 936 | ], 937 | "source": [ 938 | "tuple_example = ('age', 30) # 只读,有序\n", 939 | "print(type(tuple_example))\n", 940 | "print(tuple_example[0])\n", 941 | "print(tuple_example[1])" 942 | ] 943 | }, 944 | { 945 | "cell_type": "markdown", 946 | "metadata": {}, 947 | "source": [ 948 | "### 字典\n", 949 | "\n", 950 | "+ 字典以一种联系的方式储存信息,字典储存的是键值对(\"key-value\" pairs) ,其中任意一条信息至少和另外一条信息相联系。\n", 951 | "+ 遍历一个字典的键值对:for 结构 + mydict.items()\n", 952 | "+ 遍历一个字典的key:for 结构 + mydict\n", 953 | "+ 遍历一个字典的value:for结构 + mydict.values()\n", 954 | "+ 改变字典中的key:添加正确的——删除错误的\n", 955 | "+ 改变字典中的value:dictname['key']='newvalue'\n", 956 | "+ 在字典中增加键值对:成对添加\n", 957 | "+ 在字典中删除键值对:del dictname['key']\n" 958 | ] 959 | }, 960 | { 961 | "cell_type": "code", 962 | "execution_count": null, 963 | "metadata": {}, 964 | "outputs": [], 965 | "source": [ 966 | "dictionary_name = {key_1: value_1,\n", 967 | " key_2: value_2,\n", 968 | " key_3: value_3,\n", 969 | " }" 970 | ] 971 | }, 972 | { 973 | "cell_type": "code", 974 | "execution_count": 32, 975 | "metadata": {}, 976 | "outputs": [ 977 | { 978 | "name": "stdout", 979 | "output_type": "stream", 980 | "text": [ 981 | "\n", 982 | "Key: key_1\n", 983 | "Value: value_1\n", 984 | "\n", 985 | "Key: key_2\n", 986 | "Value: value_2\n", 987 | "\n", 988 | "Key: key_3\n", 989 | "Value: value_3\n" 990 | ] 991 | } 992 | ], 993 | "source": [ 994 | "# 以.item()函数把键值对变成了元组构成的列表\n", 995 | "# mydict.items()\n", 996 | "my_dict = {'key_1': 'value_1',\n", 997 | " 'key_2': 'value_2',\n", 998 | " 'key_3': 'value_3',\n", 999 | " }\n", 1000 | "\n", 1001 | "for key, value in my_dict.items():\n", 1002 | " print('\\nKey: %s' % key)\n", 1003 | " print('Value: %s' % value)" 1004 | ] 1005 | }, 1006 | { 1007 | "cell_type": "code", 1008 | "execution_count": null, 1009 | "metadata": {}, 1010 | "outputs": [], 1011 | "source": [ 1012 | "my_dict = {'key_1': 'value_1',\n", 1013 | " 'key_2': 'value_2',\n", 1014 | " 'key_3': 'value_3',\n", 1015 | " }\n", 1016 | "\n", 1017 | "for key in my_dict:\n", 1018 | " print('Key: %s' % key)" 1019 | ] 1020 | }, 1021 | { 1022 | "cell_type": "code", 1023 | "execution_count": null, 1024 | "metadata": {}, 1025 | "outputs": [], 1026 | "source": [ 1027 | "my_dict = {'key_1': 'value_1',\n", 1028 | " 'key_2': 'value_2',\n", 1029 | " 'key_3': 'value_3',\n", 1030 | " }\n", 1031 | "\n", 1032 | "for value in my_dict.values():\n", 1033 | " print('Value: %s' % value)" 1034 | ] 1035 | }, 1036 | { 1037 | "cell_type": "code", 1038 | "execution_count": null, 1039 | "metadata": {}, 1040 | "outputs": [], 1041 | "source": [ 1042 | "python_words = {'lisst': 'A collection of values that are not connected, but have an order.',\n", 1043 | " 'dictionary': 'A collection of key-value pairs.',\n", 1044 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 1045 | " }\n", 1046 | "\n", 1047 | "# Create a new, correct key, and connect it to the old value.\n", 1048 | "# Then delete the old key.\n", 1049 | "python_words['list'] = python_words['lisst']\n", 1050 | "\n", 1051 | "for word, meaning in python_words.items():\n", 1052 | " print(\"\\nWord: %s\" % word)\n", 1053 | " print(\"Meaning: %s\" % meaning)\n", 1054 | "\n", 1055 | "del python_words['lisst']\n", 1056 | "\n", 1057 | "# Print the dictionary, to show that the key has changed.\n", 1058 | "for word, meaning in python_words.items():\n", 1059 | " print(\"\\nWord: %s\" % word)\n", 1060 | " print(\"Meaning: %s\" % meaning)" 1061 | ] 1062 | }, 1063 | { 1064 | "cell_type": "code", 1065 | "execution_count": null, 1066 | "metadata": {}, 1067 | "outputs": [], 1068 | "source": [ 1069 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 1070 | " 'dictionary': 'A collection of key-value pairs.',\n", 1071 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 1072 | " }\n", 1073 | "\n", 1074 | "print('dictionary: ' + python_words['dictionary'])\n", 1075 | " \n", 1076 | "# Clarify one of the meanings.\n", 1077 | "python_words['dictionary'] = 'A collection of key-value pairs. Each key can be used to access its corresponding value.'\n", 1078 | "\n", 1079 | "print('\\ndictionary: ' + python_words['dictionary'])" 1080 | ] 1081 | }, 1082 | { 1083 | "cell_type": "code", 1084 | "execution_count": null, 1085 | "metadata": {}, 1086 | "outputs": [], 1087 | "source": [ 1088 | "python_words = {}\n", 1089 | "\n", 1090 | "# Fill the dictionary, pair by pair.\n", 1091 | "python_words['list'] ='A collection of values that are not connected, but have an order.'\n", 1092 | "python_words['dictionary'] = 'A collection of key-value pairs.'\n", 1093 | "python_words['function'] = 'A named set of instructions that defines a set of actions in Python.'\n", 1094 | "\n", 1095 | "# Print out the items in the dictionary.\n", 1096 | "for word, meaning in python_words.items():\n", 1097 | " print(\"\\nWord: %s\" % word)\n", 1098 | " print(\"Meaning: %s\" % meaning)" 1099 | ] 1100 | }, 1101 | { 1102 | "cell_type": "code", 1103 | "execution_count": null, 1104 | "metadata": {}, 1105 | "outputs": [], 1106 | "source": [ 1107 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 1108 | " 'dictionary': 'A collection of key-value pairs.',\n", 1109 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 1110 | " }\n", 1111 | "\n", 1112 | "# Show the current set of words and meanings.\n", 1113 | "print(\"\\n\\nThese are the Python words I know:\")\n", 1114 | "for word, meaning in python_words.items():\n", 1115 | " print(\"\\nWord: %s\" % word)\n", 1116 | " print(\"Meaning: %s\" % meaning)\n", 1117 | " \n", 1118 | "# Remove the word 'list' and its meaning.\n", 1119 | "del python_words['list']\n", 1120 | "\n", 1121 | "# Show the current set of words and meanings.\n", 1122 | "print(\"\\n\\nThese are the Python words I know:\")\n", 1123 | "for word, meaning in python_words.items():\n", 1124 | " print(\"\\nWord: %s\" % word)\n", 1125 | " print(\"Meaning: %s\" % meaning)" 1126 | ] 1127 | }, 1128 | { 1129 | "cell_type": "markdown", 1130 | "metadata": {}, 1131 | "source": [ 1132 | "### 集合\n", 1133 | "+ 集合的元素是无序的,以大括号创建,item以逗号分隔\n", 1134 | "+ 集合的元素不能重复" 1135 | ] 1136 | }, 1137 | { 1138 | "cell_type": "code", 1139 | "execution_count": 33, 1140 | "metadata": {}, 1141 | "outputs": [ 1142 | { 1143 | "name": "stdout", 1144 | "output_type": "stream", 1145 | "text": [ 1146 | "\n", 1147 | "\n" 1148 | ] 1149 | } 1150 | ], 1151 | "source": [ 1152 | "set_example1 = {'age':30}\n", 1153 | "set_example2 = {'age', 30} # 无序,可写\n", 1154 | "print(type(set_example1))\n", 1155 | "print(type(set_example2))" 1156 | ] 1157 | }, 1158 | { 1159 | "cell_type": "code", 1160 | "execution_count": 34, 1161 | "metadata": {}, 1162 | "outputs": [ 1163 | { 1164 | "name": "stdout", 1165 | "output_type": "stream", 1166 | "text": [ 1167 | "[1, 2, 1, 3]\n", 1168 | "{1, 2, 3}\n" 1169 | ] 1170 | }, 1171 | { 1172 | "data": { 1173 | "text/plain": [ 1174 | "[1, 2, 3]" 1175 | ] 1176 | }, 1177 | "execution_count": 34, 1178 | "metadata": {}, 1179 | "output_type": "execute_result" 1180 | } 1181 | ], 1182 | "source": [ 1183 | "li = [1,2,1,3] # 列表\n", 1184 | "print(li)\n", 1185 | "\n", 1186 | "se = {1,2,1,3} # 集合\n", 1187 | "print(se)\n", 1188 | "list(se)" 1189 | ] 1190 | }, 1191 | { 1192 | "cell_type": "markdown", 1193 | "metadata": {}, 1194 | "source": [ 1195 | "## 文件操作" 1196 | ] 1197 | }, 1198 | { 1199 | "cell_type": "markdown", 1200 | "metadata": {}, 1201 | "source": [ 1202 | "### with结构的文件打开方式" 1203 | ] 1204 | }, 1205 | { 1206 | "cell_type": "code", 1207 | "execution_count": 35, 1208 | "metadata": {}, 1209 | "outputs": [], 1210 | "source": [ 1211 | "with open('pi_digits.txt') as file_object:\n", 1212 | " lines = file_object.readlines()" 1213 | ] 1214 | }, 1215 | { 1216 | "cell_type": "code", 1217 | "execution_count": 36, 1218 | "metadata": {}, 1219 | "outputs": [ 1220 | { 1221 | "data": { 1222 | "text/plain": [ 1223 | "['3.1415926535\\n', ' 8979323846\\n', ' 2643383279\\n']" 1224 | ] 1225 | }, 1226 | "execution_count": 36, 1227 | "metadata": {}, 1228 | "output_type": "execute_result" 1229 | } 1230 | ], 1231 | "source": [ 1232 | "lines" 1233 | ] 1234 | }, 1235 | { 1236 | "cell_type": "markdown", 1237 | "metadata": {}, 1238 | "source": [ 1239 | "### read一族函数\n", 1240 | "\n", 1241 | "+ read() 每次读取整个文件,它通常用于将文件内容放到一个字符串变量中。\n", 1242 | " + 如果文件大于可用内存,为了保险起见,可以反复调用read(size)方法,每次最多读取size个字节的内容。\n", 1243 | "+ readlines() 自动将文件内容分析成一个行的列表.\n", 1244 | " + 该列表可以由 Python 的 for ... in ... 结构进行处理。\n", 1245 | "+ readline() 每次只读取一行,通常比readlines() 慢得多。\n", 1246 | " + 仅当没有足够内存可以一次读取整个文件时,才应该使用 readline()。" 1247 | ] 1248 | }, 1249 | { 1250 | "cell_type": "code", 1251 | "execution_count": 38, 1252 | "metadata": {}, 1253 | "outputs": [], 1254 | "source": [ 1255 | "filename = 'pi_digits.txt'\n", 1256 | "\n", 1257 | "#read()\n", 1258 | "with open(filename) as file_object:\n", 1259 | " lines = file_object.read()" 1260 | ] 1261 | }, 1262 | { 1263 | "cell_type": "code", 1264 | "execution_count": 39, 1265 | "metadata": {}, 1266 | "outputs": [ 1267 | { 1268 | "name": "stdout", 1269 | "output_type": "stream", 1270 | "text": [ 1271 | "3.1415926535\n", 1272 | " 8979323846\n", 1273 | " 2643383279\n", 1274 | "\n", 1275 | "\n" 1276 | ] 1277 | } 1278 | ], 1279 | "source": [ 1280 | "print(lines)\n", 1281 | "print(type(lines))" 1282 | ] 1283 | }, 1284 | { 1285 | "cell_type": "code", 1286 | "execution_count": 40, 1287 | "metadata": {}, 1288 | "outputs": [], 1289 | "source": [ 1290 | "# readlines\n", 1291 | "with open(filename) as file_object:\n", 1292 | " lines = file_object.readlines() " 1293 | ] 1294 | }, 1295 | { 1296 | "cell_type": "code", 1297 | "execution_count": 41, 1298 | "metadata": {}, 1299 | "outputs": [ 1300 | { 1301 | "name": "stdout", 1302 | "output_type": "stream", 1303 | "text": [ 1304 | "['3.1415926535\\n', ' 8979323846\\n', ' 2643383279\\n']\n", 1305 | "\n" 1306 | ] 1307 | } 1308 | ], 1309 | "source": [ 1310 | "print(lines)\n", 1311 | "print(type(lines)) " 1312 | ] 1313 | }, 1314 | { 1315 | "cell_type": "code", 1316 | "execution_count": 42, 1317 | "metadata": {}, 1318 | "outputs": [], 1319 | "source": [ 1320 | "with open(filename) as file_object:\n", 1321 | " lines = file_object.readline() " 1322 | ] 1323 | }, 1324 | { 1325 | "cell_type": "code", 1326 | "execution_count": 43, 1327 | "metadata": {}, 1328 | "outputs": [ 1329 | { 1330 | "name": "stdout", 1331 | "output_type": "stream", 1332 | "text": [ 1333 | "3.1415926535\n", 1334 | "\n", 1335 | "\n" 1336 | ] 1337 | } 1338 | ], 1339 | "source": [ 1340 | "print(lines)\n", 1341 | "print(type(lines))" 1342 | ] 1343 | }, 1344 | { 1345 | "cell_type": "code", 1346 | "execution_count": 44, 1347 | "metadata": {}, 1348 | "outputs": [ 1349 | { 1350 | "name": "stdout", 1351 | "output_type": "stream", 1352 | "text": [ 1353 | "3.1415926535\n", 1354 | " 8979323846\n", 1355 | " 2643383279\n" 1356 | ] 1357 | } 1358 | ], 1359 | "source": [ 1360 | "with open(filename) as file_object:\n", 1361 | " lines = file_object.readlines() \n", 1362 | " \n", 1363 | " \n", 1364 | "for line in lines:\n", 1365 | " print(line.rstrip()) " 1366 | ] 1367 | }, 1368 | { 1369 | "cell_type": "markdown", 1370 | "metadata": {}, 1371 | "source": [ 1372 | "### 添加内容\n", 1373 | "\n", 1374 | "+ write()是将字符串写入文件\n", 1375 | "+ writelines()是对列表的操作,把一个字符串列表添加到文件中" 1376 | ] 1377 | }, 1378 | { 1379 | "cell_type": "code", 1380 | "execution_count": 56, 1381 | "metadata": {}, 1382 | "outputs": [], 1383 | "source": [ 1384 | "filename = 'programming.txt'\n", 1385 | "with open(filename, 'a') as file_object:\n", 1386 | " file_object.write(\"I also love finding meaning in large datasets.\\n\")\n", 1387 | " file_object.write(\"I also love creating apps that can run in a browser.\\n\")" 1388 | ] 1389 | }, 1390 | { 1391 | "cell_type": "code", 1392 | "execution_count": 57, 1393 | "metadata": {}, 1394 | "outputs": [ 1395 | { 1396 | "name": "stdout", 1397 | "output_type": "stream", 1398 | "text": [ 1399 | "3.1415926535\n", 1400 | " 8979323846\n", 1401 | " 2643383279\n", 1402 | "I also love finding meaning in large datasets.\n", 1403 | "I also love creating apps that can run in a browser.\n", 1404 | "I also love finding meaning in large datasets.\n", 1405 | "I also love creating apps that can run in a browser.\n" 1406 | ] 1407 | } 1408 | ], 1409 | "source": [ 1410 | "with open(filename) as file_object:\n", 1411 | " lines = file_object.readlines() \n", 1412 | "for line in lines:\n", 1413 | " print(line.rstrip())" 1414 | ] 1415 | }, 1416 | { 1417 | "cell_type": "code", 1418 | "execution_count": 58, 1419 | "metadata": {}, 1420 | "outputs": [], 1421 | "source": [ 1422 | "filename = 'programming.txt'\n", 1423 | "\n", 1424 | "with open(filename, 'a') as file_object:\n", 1425 | " file_object.writelines([\"I also love finding meaning in large datasets.\\n\",\n", 1426 | " \"I also love creating apps that can run in a browser.\\n\"])\n", 1427 | " \n" 1428 | ] 1429 | }, 1430 | { 1431 | "cell_type": "code", 1432 | "execution_count": 59, 1433 | "metadata": {}, 1434 | "outputs": [ 1435 | { 1436 | "name": "stdout", 1437 | "output_type": "stream", 1438 | "text": [ 1439 | "3.1415926535\n", 1440 | " 8979323846\n", 1441 | " 2643383279\n", 1442 | "I also love finding meaning in large datasets.\n", 1443 | "I also love creating apps that can run in a browser.\n", 1444 | "I also love finding meaning in large datasets.\n", 1445 | "I also love creating apps that can run in a browser.\n", 1446 | "I also love finding meaning in large datasets.\n", 1447 | "I also love creating apps that can run in a browser.\n" 1448 | ] 1449 | } 1450 | ], 1451 | "source": [ 1452 | "with open(filename) as file_object:\n", 1453 | " lines = file_object.readlines() \n", 1454 | "for line in lines:\n", 1455 | " print(line.rstrip())" 1456 | ] 1457 | }, 1458 | { 1459 | "cell_type": "markdown", 1460 | "metadata": {}, 1461 | "source": [ 1462 | "### 生成新文件或覆盖旧文件内容" 1463 | ] 1464 | }, 1465 | { 1466 | "cell_type": "code", 1467 | "execution_count": 47, 1468 | "metadata": {}, 1469 | "outputs": [], 1470 | "source": [ 1471 | "with open('test.txt', 'w') as wt:\n", 1472 | " wt.write('Hello, world!')" 1473 | ] 1474 | }, 1475 | { 1476 | "cell_type": "code", 1477 | "execution_count": 48, 1478 | "metadata": {}, 1479 | "outputs": [], 1480 | "source": [ 1481 | "with open('test.txt', 'w') as wt:\n", 1482 | " wt.write('Hello, Python!')" 1483 | ] 1484 | }, 1485 | { 1486 | "cell_type": "code", 1487 | "execution_count": null, 1488 | "metadata": {}, 1489 | "outputs": [], 1490 | "source": [] 1491 | }, 1492 | { 1493 | "cell_type": "code", 1494 | "execution_count": null, 1495 | "metadata": {}, 1496 | "outputs": [], 1497 | "source": [] 1498 | }, 1499 | { 1500 | "cell_type": "code", 1501 | "execution_count": null, 1502 | "metadata": {}, 1503 | "outputs": [], 1504 | "source": [] 1505 | }, 1506 | { 1507 | "cell_type": "code", 1508 | "execution_count": null, 1509 | "metadata": {}, 1510 | "outputs": [], 1511 | "source": [] 1512 | }, 1513 | { 1514 | "cell_type": "code", 1515 | "execution_count": null, 1516 | "metadata": {}, 1517 | "outputs": [], 1518 | "source": [] 1519 | }, 1520 | { 1521 | "cell_type": "code", 1522 | "execution_count": null, 1523 | "metadata": {}, 1524 | "outputs": [], 1525 | "source": [] 1526 | } 1527 | ], 1528 | "metadata": { 1529 | "kernelspec": { 1530 | "display_name": "Python 3", 1531 | "language": "python", 1532 | "name": "python3" 1533 | }, 1534 | "language_info": { 1535 | "codemirror_mode": { 1536 | "name": "ipython", 1537 | "version": 3 1538 | }, 1539 | "file_extension": ".py", 1540 | "mimetype": "text/x-python", 1541 | "name": "python", 1542 | "nbconvert_exporter": "python", 1543 | "pygments_lexer": "ipython3", 1544 | "version": "3.6.6" 1545 | }, 1546 | "toc": { 1547 | "base_numbering": 1, 1548 | "nav_menu": {}, 1549 | "number_sections": true, 1550 | "sideBar": true, 1551 | "skip_h1_title": false, 1552 | "title_cell": "Table of Contents", 1553 | "title_sidebar": "Contents", 1554 | "toc_cell": false, 1555 | "toc_position": { 1556 | "height": "563px", 1557 | "left": "731px", 1558 | "top": "158px", 1559 | "width": "216px" 1560 | }, 1561 | "toc_section_display": true, 1562 | "toc_window_display": true 1563 | } 1564 | }, 1565 | "nbformat": 4, 1566 | "nbformat_minor": 2 1567 | } 1568 | -------------------------------------------------------------------------------- /CEPS.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/CEPS.csv -------------------------------------------------------------------------------- /ForestData.csv: -------------------------------------------------------------------------------- 1 | X,Y,month,day,temp,RH,wind,rain,area 2 | 1,2,aug,fri,14.7,66,2.7,0,0 3 | 1,2,aug,fri,18.5,73,8.5,0,0 4 | 1,2,aug,fri,25.9,41,3.6,0,0 5 | 1,2,aug,sat,25.9,32,3.1,0,0 6 | 1,2,aug,sun,19.5,39,6.3,0,0 7 | 1,2,aug,sun,17.9,44,2.2,0,0 8 | 1,2,aug,thu,20.2,45,3.6,0,0 9 | 1,2,aug,thu,26.7,35,1.8,0,5.8 10 | 1,2,aug,tue,21.6,19,6.7,0,0 11 | 1,2,aug,tue,18.6,51,4.5,0,0 12 | 1,2,aug,wed,16.6,47,0.9,0,0 13 | 1,2,aug,wed,23.3,31,4.5,0,0.55 14 | 1,2,jul,fri,14.8,78,8,0,0 15 | 1,2,jul,sat,16.6,53,5.4,0,0.71 16 | 1,2,sep,sun,25.3,36,3.6,0,0 17 | 1,2,sep,thu,21.5,15,0.9,0,0 18 | 1,2,sep,thu,25.4,27,2.2,0,0 19 | 1,2,sep,thu,22.4,34,2.2,0,0 20 | 1,2,sep,tue,18.8,40,2.2,0,212.88 21 | 1,3,aug,fri,32.4,27,2.2,0,0 22 | 1,3,aug,fri,27.5,29,4.5,0,43.32 23 | 1,3,aug,sat,23.3,40,4,0,6.36 24 | 1,3,aug,thu,26.2,34,5.8,0,0 25 | 1,3,mar,mon,8.3,72,3.1,0,0 26 | 1,3,sep,fri,19.1,46,2.2,0,0.33 27 | 1,3,sep,mon,12.4,73,6.3,0,30.32 28 | 1,3,sep,sat,22.3,48,4,0,0.72 29 | 1,3,sep,sun,23.9,32,6.7,0,5.33 30 | 1,3,sep,sun,21.9,43,4,0,70.76 31 | 1,4,aug,fri,22.2,45,3.6,0,0 32 | 1,4,aug,fri,11.8,88,4.9,0,9.71 33 | 1,4,aug,sat,14.2,53,1.8,0,3.5 34 | 1,4,aug,sat,20.3,39,4.9,0,4.53 35 | 1,4,aug,sat,25.6,42,4,0,0 36 | 1,4,aug,wed,19.9,50,4,0,82.75 37 | 1,4,jul,tue,23.4,31,5.4,0,0 38 | 1,4,sep,fri,21.1,39,2.2,0,8.12 39 | 1,4,sep,mon,18.1,54,3.1,0,2.13 40 | 1,4,sep,mon,21.3,35,2.2,0,28.19 41 | 1,4,sep,sat,24.2,27,3.1,0,0 42 | 1,4,sep,sun,19,52,2.2,0,0 43 | 1,4,sep,sun,14.5,76,7.6,0,3.71 44 | 1,4,sep,thu,16.8,28,4,0,7.21 45 | 1,4,sep,tue,21.7,38,2.2,0,0.43 46 | 1,5,sep,mon,21,42,2.2,0,7.3 47 | 1,5,sep,sat,29.6,27,2.7,0,1.46 48 | 1,5,sep,sun,27.8,27,3.1,0,95.18 49 | 1,5,sep,tue,21.6,33,2.2,0,11.53 50 | 2,2,aug,mon,23.1,31,3.1,0,0 51 | 2,2,aug,sat,22.9,31,7.2,0,15.45 52 | 2,2,aug,sat,21.9,42,2.2,0,174.63 53 | 2,2,aug,sun,20.8,33,2.7,0,0 54 | 2,2,aug,thu,18.8,35,4.9,0,0 55 | 2,2,aug,thu,18.6,44,4.5,0,0 56 | 2,2,aug,thu,20.4,56,2.2,0,0 57 | 2,2,aug,tue,17.4,43,6.7,0,1.07 58 | 2,2,aug,tue,24.6,22,4.5,0,8.71 59 | 2,2,aug,tue,24.6,22,4.5,0,10.01 60 | 2,2,aug,tue,23.7,24,3.1,0,0 61 | 2,2,aug,tue,21.8,56,3.1,0,0.52 62 | 2,2,aug,tue,27.9,27,2.2,0,0 63 | 2,2,aug,wed,18.4,45,3.6,0,1.63 64 | 2,2,feb,fri,12.3,51,0.9,0,0 65 | 2,2,feb,mon,13.9,40,5.4,0,0 66 | 2,2,feb,sat,4.6,59,0.9,0,6.84 67 | 2,2,jul,fri,13.4,79,3.6,0,37.02 68 | 2,2,mar,sun,11.5,39,5.8,0,0 69 | 2,2,mar,sun,5.5,59,6.3,0,0 70 | 2,2,sep,fri,23,37,4.5,0,0 71 | 2,2,sep,fri,19.6,33,5.4,0,0 72 | 2,2,sep,fri,19.6,33,6.3,0,0 73 | 2,2,sep,mon,16.8,43,3.1,0,5.83 74 | 2,2,sep,sat,18.2,46,1.8,0,200.94 75 | 2,3,sep,mon,18,51,5.4,0,0 76 | 2,4,aug,fri,21.4,42,3.1,0,4.25 77 | 2,4,aug,fri,25.9,41,3.6,0,0 78 | 2,4,aug,mon,28.3,32,4,0,8.85 79 | 2,4,aug,mon,27.9,33,2.2,0,2.35 80 | 2,4,aug,mon,30.6,28,3.6,0,2.07 81 | 2,4,aug,sun,15.4,66,4,0,10.13 82 | 2,4,aug,sun,22.4,54,7.6,0,2.87 83 | 2,4,aug,sun,20.9,50,2.2,0,16 84 | 2,4,aug,sun,24.9,42,5.4,0,2.44 85 | 2,4,aug,sun,20.9,66,4.9,0,15.34 86 | 2,4,aug,sun,21.9,71,5.8,0,54.29 87 | 2,4,aug,thu,16.6,59,2.7,0,0 88 | 2,4,aug,tue,20.1,40,4,0,0 89 | 2,4,aug,wed,20.5,35,4,0,1.64 90 | 2,4,aug,wed,20.7,70,2.2,0,0.75 91 | 2,4,aug,wed,30.8,19,4.5,0,0 92 | 2,4,aug,wed,29.2,30,4.9,0,1.95 93 | 2,4,jan,sat,5.3,78,3.1,0,0 94 | 2,4,mar,tue,15.2,19,7.6,0,0 95 | 2,4,sep,mon,22.6,38,3.6,0,11.32 96 | 2,4,sep,mon,20.4,41,1.8,0,1.47 97 | 2,4,sep,sat,24.1,29,4.5,0,0 98 | 2,4,sep,sat,28.6,27,2.2,0,1.61 99 | 2,4,sep,sun,16,45,1.8,0,0 100 | 2,4,sep,sun,24.9,27,2.2,0,0 101 | 2,4,sep,sun,12.2,78,6.3,0,0 102 | 2,4,sep,wed,21.8,34,2.2,0,6.04 103 | 2,5,aug,fri,23.5,36,5.4,0,10.02 104 | 2,5,aug,sat,23.6,53,4,0,6.43 105 | 2,5,aug,sat,18.9,64,4.9,0,0 106 | 2,5,aug,sun,19.2,44,2.7,0,4.69 107 | 2,5,aug,sun,24.8,36,4,0,3.05 108 | 2,5,aug,sun,33.1,25,4,0,26.43 109 | 2,5,aug,thu,24.2,28,2.7,0,8.68 110 | 2,5,aug,thu,22.3,46,4,0,0 111 | 2,5,aug,tue,20.2,47,4,0,3.09 112 | 2,5,aug,wed,23.8,32,5.4,0,0.77 113 | 2,5,jul,sat,18.7,53,1.8,0,0 114 | 2,5,jul,sat,23.8,51,1.8,0,0 115 | 2,5,jul,sun,23.4,40,6.3,0,0 116 | 2,5,jun,thu,22.7,40,9.4,0,3.19 117 | 2,5,oct,sun,15.4,35,0.9,0,0 118 | 2,5,sep,fri,16.2,58,3.6,0,9.96 119 | 2,5,sep,mon,21.9,39,1.8,0,0.47 120 | 2,5,sep,mon,19.3,44,2.2,0,3.93 121 | 2,5,sep,tue,17.6,46,3.1,0,7.04 122 | 2,5,sep,wed,18.3,45,2.2,0,4.88 123 | 3,3,sep,sat,24.2,27,3.1,0,6.58 124 | 3,4,aug,fri,11.2,84,7.6,0,3.3 125 | 3,4,aug,mon,10.3,74,2.2,0,0 126 | 3,4,aug,mon,17.1,43,5.4,0,0 127 | 3,4,aug,sat,20.6,59,0.9,0,0 128 | 3,4,aug,sun,11.6,87,4.5,0,0 129 | 3,4,aug,sun,19.8,39,5.4,0,0 130 | 3,4,aug,sun,19.8,39,5.4,0,0 131 | 3,4,aug,sun,26.8,38,6.3,0,0.76 132 | 3,4,aug,sun,24.6,44,4,0,3.2 133 | 3,4,aug,sun,23.4,40,5.8,0,1.29 134 | 3,4,aug,thu,19.6,36,3.1,0,0 135 | 3,4,aug,thu,16.8,56,3.1,0,0 136 | 3,4,aug,tue,14.4,66,5.4,0,0 137 | 3,4,aug,tue,21,32,3.1,0,0 138 | 3,4,aug,tue,32.3,27,2.2,0,14.68 139 | 3,4,aug,wed,21.7,40,0.4,0,2.47 140 | 3,4,dec,mon,4.6,21,8.5,0,10.73 141 | 3,4,feb,sat,12.7,48,1.8,0,0 142 | 3,4,feb,wed,8.8,35,3.1,0,1.1 143 | 3,4,jul,mon,17.9,48,2.7,0,0 144 | 3,4,jul,sat,24.6,43,1.8,0,1.43 145 | 3,4,jul,wed,14.2,58,4,0,0 146 | 3,4,mar,fri,18.8,18,4.5,0,0 147 | 3,4,mar,mon,10.6,30,4,0,0 148 | 3,4,mar,sat,17.4,24,5.4,0,0 149 | 3,4,mar,sat,11.6,30,6.3,0,0 150 | 3,4,mar,sat,15.2,27,4.9,0,0 151 | 3,4,mar,tue,15.8,27,7.6,0,0 152 | 3,4,mar,wed,8.9,35,8,0,0 153 | 3,4,mar,wed,11.2,41,5.4,0,5.55 154 | 3,4,oct,sun,20.6,24,5.4,0,0 155 | 3,4,sep,fri,19.8,50,5.4,0,0 156 | 3,4,sep,fri,18.6,49,3.6,0,35.88 157 | 3,4,sep,fri,17.4,57,4.5,0,0 158 | 3,4,sep,mon,18.9,35,2.7,0,0 159 | 3,4,sep,sun,22.8,39,3.6,0,0 160 | 3,4,sep,sun,22.5,42,5.4,0,0 161 | 3,4,sep,sun,23.8,35,3.6,0,5.18 162 | 3,4,sep,sun,20.6,55,5.4,0,24.59 163 | 3,4,sep,thu,22.8,46,4,0,4.95 164 | 3,4,sep,tue,17.9,45,3.1,0,0 165 | 3,4,sep,tue,13.9,59,6.3,0,11.24 166 | 3,4,sep,wed,18.5,30,2.7,0,0 167 | 3,5,aug,sat,17.6,52,5.8,0,0 168 | 3,5,mar,mon,9,49,2.2,0,0 169 | 3,5,mar,tue,15.5,27,6.3,0,0 170 | 3,5,mar,tue,14.9,38,2.7,0,0 171 | 3,5,oct,wed,15.9,46,3.6,0,0 172 | 3,5,sep,fri,17.2,43,3.1,0,0 173 | 3,5,sep,thu,12.9,39,2.7,0,2.18 174 | 3,6,jun,fri,19.2,38,4.5,0,0 175 | 3,6,jun,fri,19.2,38,4.5,0,0 176 | 3,6,sep,mon,15.6,66,3.1,0,0 177 | 3,6,sep,sun,17.2,58,1.3,0,0 178 | 4,3,aug,sat,21.4,44,2.7,0,0.68 179 | 4,3,aug,sun,21.5,34,2.2,0,0 180 | 4,3,aug,sun,27.8,32,2.7,0,6.44 181 | 4,3,aug,thu,17.6,45,3.6,0,0 182 | 4,3,aug,wed,20.4,42,4.9,0,0 183 | 4,3,aug,wed,20.4,42,4.9,0,0 184 | 4,3,aug,wed,28.9,29,4.9,0,49.59 185 | 4,3,jul,sun,26.1,45,4,0,7.36 186 | 4,3,jul,thu,27.2,28,1.3,0,1.76 187 | 4,3,jul,thu,30.2,22,4.9,0,0 188 | 4,3,jun,thu,26.4,35,2.7,0,10.08 189 | 4,3,mar,mon,11,46,5.8,0,36.85 190 | 4,3,may,fri,18,40,4,0,38.48 191 | 4,3,oct,sun,13.8,50,2.7,0,0 192 | 4,3,sep,fri,17.3,45,4,0,3.94 193 | 4,3,sep,fri,19.9,44,3.1,0,7.8 194 | 4,3,sep,mon,9.8,86,1.8,0,0 195 | 4,3,sep,sat,23.5,27,4,0,3.33 196 | 4,3,sep,sun,20.4,55,4.9,0,3.64 197 | 4,3,sep,thu,27.7,24,2.2,0,0 198 | 4,3,sep,tue,17.8,63,4.9,0,0 199 | 4,3,sep,tue,15.9,53,2.2,0,2.93 200 | 4,4,apr,fri,16.7,20,3.1,0,0 201 | 4,4,aug,fri,21.8,53,3.1,0,6.54 202 | 4,4,aug,sat,18.4,42,6.7,0,0 203 | 4,4,aug,thu,32.4,21,4.5,0,0 204 | 4,4,aug,tue,16.6,54,5.4,0,0 205 | 4,4,aug,tue,22.1,54,7.6,0,0.79 206 | 4,4,aug,tue,19.1,53,2.7,0,4.4 207 | 4,4,aug,tue,19.4,71,7.6,0,46.7 208 | 4,4,aug,tue,20.7,69,4.9,0.4,0 209 | 4,4,aug,wed,20.6,58,1.3,0,0 210 | 4,4,aug,wed,28.7,33,4,0,0 211 | 4,4,dec,mon,4.6,21,8.5,0,17.85 212 | 4,4,dec,mon,4.6,21,8.5,0,22.03 213 | 4,4,dec,mon,4.6,21,8.5,0,9.77 214 | 4,4,jul,tue,23.3,37,3.1,0,0 215 | 4,4,mar,fri,13.7,43,5.8,0,0 216 | 4,4,mar,mon,11.8,35,1.8,0,0 217 | 4,4,mar,mon,11,46,5.8,0,0 218 | 4,4,mar,sat,17,27,4.9,0,28.66 219 | 4,4,mar,sat,17,27,4.9,0,28.66 220 | 4,4,mar,tue,14.1,43,2.7,0,0 221 | 4,4,oct,sat,18.4,25,3.1,0,24.23 222 | 4,4,sep,fri,15.4,53,6.3,0,7.31 223 | 4,4,sep,fri,20.8,35,4.9,0,13.06 224 | 4,4,sep,fri,20.8,35,4.9,0,1.26 225 | 4,4,sep,mon,17.7,39,2.2,0,3.07 226 | 4,4,sep,sat,19.6,48,2.7,0,0 227 | 4,4,sep,sat,17.1,41,2.2,0,11.22 228 | 4,4,sep,sun,17.8,64,1.3,0,0 229 | 4,4,sep,sun,16.9,60,1.3,0,29.48 230 | 4,4,sep,sun,22.9,39,4.9,0,48.55 231 | 4,4,sep,thu,20.8,17,1.3,0,0 232 | 4,4,sep,thu,19.2,24,4.9,0,3.78 233 | 4,4,sep,wed,12.9,74,4.9,0,0 234 | 4,4,sep,wed,26.4,21,4.5,0,88.49 235 | 4,4,sep,wed,19.7,41,1.8,0,1.58 236 | 4,5,aug,mon,32.6,26,3.1,0,2.77 237 | 4,5,aug,sun,21.4,33,3.1,0,0 238 | 4,5,aug,sun,10.4,75,0.9,0,0 239 | 4,5,aug,thu,17.4,54,3.1,0,0 240 | 4,5,aug,wed,23.4,49,5.4,0,6.43 241 | 4,5,feb,sat,14.2,46,4,0,0 242 | 4,5,feb,sun,10.1,62,1.8,0,51.78 243 | 4,5,jan,sun,5.2,100,0.9,0,0 244 | 4,5,jul,fri,22.9,40,1.3,0,2.64 245 | 4,5,mar,fri,17.2,26,4.5,0,0 246 | 4,5,mar,fri,15.8,27,7.6,0,0 247 | 4,5,mar,fri,12.7,52,6.3,0,0 248 | 4,5,mar,thu,18.2,29,3.1,0,0 249 | 4,5,sep,fri,17.7,37,3.6,0,0 250 | 4,5,sep,mon,17.4,56,5.4,0,0 251 | 4,5,sep,sat,20.3,45,3.1,0,0 252 | 4,5,sep,sat,17.7,25,3.1,0,154.88 253 | 4,5,sep,sun,13.8,77,7.6,0,0 254 | 4,5,sep,thu,21.5,15,0.9,0,11.06 255 | 4,5,sep,thu,22.1,34,1.8,0,14.57 256 | 4,5,sep,thu,18.6,24,5.8,0,0 257 | 4,5,sep,tue,15.9,38,5.4,0,1.75 258 | 4,5,sep,tue,16.4,27,3.6,0,0 259 | 4,5,sep,wed,24.3,25,4,0,9.41 260 | 4,5,sep,wed,19.4,19,1.3,0,31.72 261 | 4,6,dec,fri,2.2,59,4.9,0,9.27 262 | 4,6,dec,sun,4.8,57,8.5,0,8.98 263 | 4,6,dec,thu,5.1,61,4.9,0,5.38 264 | 4,6,feb,sat,15.4,40,2.7,0,0 265 | 4,6,mar,mon,14,39,3.1,0,0 266 | 4,6,mar,sun,10.6,46,4.9,0,0 267 | 4,6,sep,sun,28.3,26,3.1,0,64.1 268 | 4,6,sep,thu,17.6,42,3.1,0,0 269 | 5,4,apr,sun,17.6,27,5.8,0,0 270 | 5,4,aug,fri,21.1,71,7.6,1.4,2.17 271 | 5,4,aug,sun,25.7,39,5.4,0,0.09 272 | 5,4,aug,sun,24.1,50,4,0,0 273 | 5,4,aug,thu,20.3,42,2.7,0,0 274 | 5,4,aug,tue,17.3,43,4.5,0,0 275 | 5,4,aug,tue,24.1,43,6.3,0,2 276 | 5,4,aug,tue,26.4,34,3.6,0,16.4 277 | 5,4,feb,fri,7.5,46,8,0,24.24 278 | 5,4,feb,sun,12.4,53,2.2,0,6.38 279 | 5,4,jul,wed,19.3,39,7.2,0,7.73 280 | 5,4,mar,fri,15.6,25,6.3,0,0 281 | 5,4,mar,mon,13.2,40,5.4,0,0.95 282 | 5,4,sep,fri,27.6,30,1.3,0,0 283 | 5,4,sep,fri,20.1,47,4.9,0,1.46 284 | 5,4,sep,fri,10.1,75,3.6,0,0 285 | 5,4,sep,fri,12.8,64,3.6,0,1.64 286 | 5,4,sep,fri,10.1,75,3.6,0,3.71 287 | 5,4,sep,fri,16.2,58,3.6,0,0 288 | 5,4,sep,mon,19.1,38,2.7,0,0 289 | 5,4,sep,sat,24.1,27,3.1,0,0 290 | 5,4,sep,thu,21.6,28,6.3,0,4.41 291 | 5,4,sep,wed,21.9,35,1.8,0,2.57 292 | 5,5,aug,sun,17.3,80,4.5,0,0 293 | 5,5,mar,sat,15.1,27,5.4,0,0 294 | 5,5,mar,thu,11.6,48,5.4,0,0 295 | 5,6,aug,sun,24.3,33,3.6,0,3.63 296 | 5,6,mar,sat,15.1,64,4,0,13.99 297 | 5,6,sep,mon,14.7,70,3.6,0,0 298 | 5,6,sep,wed,25.9,24,4,0,0 299 | 6,3,apr,sun,13.7,33,9.4,0,61.13 300 | 6,3,apr,wed,15.2,51,2.7,0,0 301 | 6,3,aug,fri,19.3,39,3.6,0,1.56 302 | 6,3,aug,thu,18.9,41,3.1,0,10.34 303 | 6,3,feb,fri,14.7,42,2.7,0,0 304 | 6,3,feb,sun,4.2,51,4,0,0 305 | 6,3,jul,tue,26.3,39,3.1,0,7.02 306 | 6,3,mar,sat,15.2,31,8.5,0,1.94 307 | 6,3,nov,tue,11.8,31,4.5,0,0 308 | 6,3,oct,tue,21.7,24,4.5,0,0 309 | 6,3,sep,fri,25.4,24,3.6,0,0 310 | 6,3,sep,fri,20.6,37,1.8,0,0 311 | 6,3,sep,fri,15.9,55,3.6,0,0 312 | 6,3,sep,fri,19.7,39,2.7,0,0 313 | 6,3,sep,mon,11.2,78,7.6,0,0 314 | 6,3,sep,mon,21.2,32,2.7,0,0 315 | 6,3,sep,mon,23,34,2.2,0,56.04 316 | 6,3,sep,mon,20.6,37,1.8,0,0 317 | 6,3,sep,mon,12.2,66,4.9,0,6.1 318 | 6,3,sep,sat,30.2,24,2.7,0,0 319 | 6,3,sep,sun,22.8,39,3.6,0,0 320 | 6,3,sep,sun,17.7,39,3.6,0,0 321 | 6,3,sep,sun,24.8,28,1.8,0,14.29 322 | 6,3,sep,thu,18.9,34,7.2,0,34.36 323 | 6,3,sep,tue,18.2,62,4.5,0,0 324 | 6,4,apr,sat,9.3,44,4.5,0,0 325 | 6,4,aug,fri,23.3,34,3.1,0,28.74 326 | 6,4,aug,thu,20.3,41,4,0,1.9 327 | 6,4,feb,tue,5.1,77,5.4,0,2.14 328 | 6,4,jun,sun,14.3,46,1.8,0,0.9 329 | 6,4,mar,sat,13.3,42,0.9,0,7.4 330 | 6,4,mar,wed,15.9,35,4,0,0 331 | 6,4,sep,tue,18.3,40,2.7,0,0 332 | 6,4,sep,tue,18.7,43,2.7,0,103.39 333 | 6,5,apr,mon,10.9,64,3.1,0,3.35 334 | 6,5,apr,thu,5.8,54,5.8,0,4.61 335 | 6,5,apr,thu,5.8,54,5.8,0,10.93 336 | 6,5,aug,fri,17,72,6.7,0,0 337 | 6,5,aug,fri,18.2,62,5.4,0,0.43 338 | 6,5,aug,sat,14.7,59,5.8,0,0 339 | 6,5,aug,sun,19.1,70,2.2,0,0 340 | 6,5,aug,thu,27.4,22,4,0,0.9 341 | 6,5,aug,tue,19.4,55,4,0,0.17 342 | 6,5,aug,tue,33.3,26,2.7,0,40.54 343 | 6,5,aug,wed,16.6,47,0.9,0,2.29 344 | 6,5,aug,wed,23.4,33,4.5,0,2.51 345 | 6,5,aug,wed,22.1,37,3.6,0,0.21 346 | 6,5,dec,tue,5.1,24,8.5,0,24.77 347 | 6,5,feb,mon,5.3,68,1.8,0,0 348 | 6,5,feb,tue,4.6,82,6.3,0,5.39 349 | 6,5,jun,fri,23.2,39,5.4,0,1.19 350 | 6,5,jun,mon,20.7,25,4.9,0,0 351 | 6,5,jun,mon,19.1,39,5.4,0,3.52 352 | 6,5,jun,sat,10.6,90,2.7,0,0 353 | 6,5,mar,fri,14.6,26,9.4,0,2.53 354 | 6,5,mar,fri,11.7,33,4,0,8.31 355 | 6,5,mar,mon,15.2,27,3.1,0,31.86 356 | 6,5,mar,mon,10.2,45,5.8,0,3.18 357 | 6,5,mar,sat,17.4,25,4.9,0,0 358 | 6,5,mar,sun,12.4,54,3.6,0,12.1 359 | 6,5,mar,thu,5.3,70,4.5,0,2.14 360 | 6,5,mar,thu,8.7,51,5.8,0,0 361 | 6,5,mar,thu,13.3,27,3.6,0,6.61 362 | 6,5,mar,wed,13.8,24,5.8,0,0 363 | 6,5,may,sat,11.3,94,4.9,0,0 364 | 6,5,sep,fri,22.9,44,5.4,0,0 365 | 6,5,sep,fri,19.6,33,6.3,0,19.23 366 | 6,5,sep,fri,18.4,42,2.2,0,1.09 367 | 6,5,sep,fri,10.3,78,4,0,18.3 368 | 6,5,sep,mon,21.3,42,2.2,0,0 369 | 6,5,sep,sat,25.1,27,4,0,1090.84 370 | 6,5,sep,sat,21.2,32,2.2,0,0 371 | 6,5,sep,sat,19.7,35,1.8,0,0 372 | 6,5,sep,sat,16.8,47,4.9,0,12.64 373 | 6,5,sep,sat,15.4,57,4.9,0,39.35 374 | 6,5,sep,sat,17,67,4.9,0,3.95 375 | 6,5,sep,thu,21.6,27,2.2,0,0 376 | 6,5,sep,thu,16.8,28,4,0,1.01 377 | 6,5,sep,thu,13.7,56,1.8,0,4.42 378 | 6,5,sep,tue,21.1,35,2.7,0,5.65 379 | 6,5,sep,tue,19.6,45,3.1,0,20.03 380 | 6,5,sep,wed,26.4,21,4.5,0,0 381 | 6,5,sep,wed,24.3,27,4.9,0,0 382 | 6,6,aug,mon,23.9,42,2.2,0,0 383 | 6,6,aug,sat,30.8,30,4.9,0,8.59 384 | 6,6,jul,mon,23,36,3.1,0,0 385 | 7,3,mar,mon,11,46,5.8,0,27.35 386 | 7,3,oct,sat,17.8,27,4,0,0 387 | 7,4,aug,fri,23.3,34,3.1,0,0 388 | 7,4,aug,mon,17.7,65,4,0,0 389 | 7,4,aug,sat,19.5,43,5.8,0,0 390 | 7,4,aug,sat,23.7,32,5.8,0,0 391 | 7,4,aug,sat,5.1,96,5.8,0,26 392 | 7,4,aug,sat,23.7,40,1.8,0,1.38 393 | 7,4,aug,sat,15.5,72,8,0,1.94 394 | 7,4,aug,sun,16.3,60,5.4,0,0 395 | 7,4,aug,sun,16.4,47,1.3,0,1.56 396 | 7,4,aug,sun,20.1,39,5.4,0,2.74 397 | 7,4,aug,sun,21.9,73,7.6,1,0 398 | 7,4,aug,sun,19.3,61,4.9,0,0 399 | 7,4,aug,sun,21.2,70,6.7,0,11.16 400 | 7,4,aug,thu,21.4,38,2.7,0,1.52 401 | 7,4,feb,fri,8.2,53,9.4,0,4.62 402 | 7,4,feb,mon,7.5,71,6.3,0,9.96 403 | 7,4,feb,sun,8.8,68,2.2,0,13.05 404 | 7,4,jul,mon,22.6,57,4.9,0,278.53 405 | 7,4,jul,sat,22.1,49,2.7,0,0 406 | 7,4,jul,sat,24.2,32,1.8,0,0 407 | 7,4,jul,sat,24.3,30,1.8,0,0 408 | 7,4,jul,sun,18.2,82,4.5,0,2.21 409 | 7,4,jun,sun,21,44,4.5,0,0 410 | 7,4,mar,mon,16.1,29,3.1,0,1.75 411 | 7,4,mar,sun,11.5,60,4,0,8.24 412 | 7,4,oct,fri,11.3,60,5.4,0,0 413 | 7,4,oct,mon,16.8,45,4.5,0,6.83 414 | 7,4,oct,sat,14.6,33,1.3,0,0 415 | 7,4,oct,tue,18,33,0.9,0,0 416 | 7,4,sep,fri,19,34,5.8,0,0 417 | 7,4,sep,fri,19,34,5.8,0,1.69 418 | 7,4,sep,fri,20.1,47,4.9,0,26.13 419 | 7,4,sep,fri,20.6,43,3.6,0,2.03 420 | 7,4,sep,fri,19.8,47,2.7,0,1.72 421 | 7,4,sep,fri,18.7,50,2.2,0,5.97 422 | 7,4,sep,fri,15.2,64,3.1,0,0.52 423 | 7,4,sep,mon,19.4,48,1.3,0,0 424 | 7,4,sep,mon,19.3,44,2.2,0,0 425 | 7,4,sep,sat,21.5,28,4.5,0,15.64 426 | 7,4,sep,sun,17.1,53,5.4,0,0.41 427 | 7,4,sep,sun,25.3,27,2.7,0,0 428 | 7,4,sep,sun,13.8,77,7.6,0,11.06 429 | 7,4,sep,thu,19.4,45,3.6,0,0 430 | 7,4,sep,wed,15.4,57,4.5,0,37.71 431 | 7,4,sep,wed,10.5,77,4,0,0 432 | 7,5,apr,sun,13.4,75,1.8,0,0 433 | 7,5,aug,sat,26.4,33,3.6,0,0 434 | 7,5,aug,tue,27.3,63,4.9,6.4,10.82 435 | 7,5,aug,tue,21.6,65,4.9,0.8,0 436 | 7,5,jun,sun,22.2,48,1.3,0,0 437 | 7,5,mar,fri,8.2,51,6.7,0,0 438 | 7,5,oct,mon,16.1,44,4,0,49.37 439 | 7,5,sep,sat,22.8,40,4,0,0 440 | 7,5,sep,sat,17.8,51,7.2,0,0 441 | 7,5,sep,sat,19.3,38,4,0,0 442 | 7,5,sep,tue,20.7,37,2.2,0,17.2 443 | 7,6,jul,tue,26.9,28,5.4,0,86.45 444 | 7,6,jul,wed,12.6,90,7.6,0.2,0 445 | 8,3,jun,mon,14.3,79,4,0,1.94 446 | 8,3,sep,thu,23.2,26,4.9,0,23.41 447 | 8,3,sep,tue,24.2,28,3.6,0,0.96 448 | 8,4,aug,sat,21.3,44,4.5,0,12.18 449 | 8,5,aug,wed,26.8,25,3.1,0,0.68 450 | 8,5,aug,wed,24,36,3.1,0,0.24 451 | 8,5,oct,mon,16.7,47,4.9,0,0 452 | 8,5,sep,sun,17.8,67,2.2,0,2.01 453 | 8,6,aug,fri,21.2,51,8.9,0,0.61 454 | 8,6,aug,fri,20.8,34,4.9,0,6.96 455 | 8,6,aug,mon,24.1,27,3.1,0,0 456 | 8,6,aug,mon,8,86,2.2,0,0 457 | 8,6,aug,mon,23.4,22,2.7,0,0 458 | 8,6,aug,mon,21.1,54,2.2,0,0 459 | 8,6,aug,mon,26.8,35,1.3,0,0.54 460 | 8,6,aug,mon,25.5,29,1.8,0,1.23 461 | 8,6,aug,sat,20.1,34,4.5,0,58.3 462 | 8,6,aug,sat,16.4,43,4,0,71.3 463 | 8,6,aug,sat,23.9,41,2.2,0,8.02 464 | 8,6,aug,sat,26.9,31,3.6,0,4.96 465 | 8,6,aug,sat,14.2,73,2.7,0,0 466 | 8,6,aug,sat,18.9,64,4.9,0,3.32 467 | 8,6,aug,sat,18.9,64,4.9,0,0 468 | 8,6,aug,sun,22.2,29,5.4,0,0 469 | 8,6,aug,sun,20.8,32,6.3,0,0 470 | 8,6,aug,sun,18.2,43,4.9,0,0 471 | 8,6,aug,sun,16.2,59,3.1,0,32.07 472 | 8,6,aug,sun,19.6,41,5.8,0,196.48 473 | 8,6,aug,sun,31,27,5.4,0,0 474 | 8,6,aug,sun,27.8,35,2.7,0,0 475 | 8,6,aug,thu,20.7,45,2.2,0,2.55 476 | 8,6,aug,thu,16.2,63,2.7,0,16.33 477 | 8,6,aug,thu,21.3,41,3.6,0,0 478 | 8,6,aug,thu,27.5,27,4.9,0,746.28 479 | 8,6,aug,thu,20.4,56,2.2,0,0 480 | 8,6,aug,thu,23.9,38,6.7,0,0 481 | 8,6,aug,tue,14.4,66,5.4,0,5.23 482 | 8,6,aug,tue,20.1,58,4.5,0,9.27 483 | 8,6,aug,tue,21.6,65,4.9,0.8,0 484 | 8,6,aug,wed,17.4,50,4,0,2.69 485 | 8,6,aug,wed,28.7,28,2.7,0,0 486 | 8,6,aug,wed,28.2,29,1.8,0,5.86 487 | 8,6,dec,wed,5.1,61,8,0,11.19 488 | 8,6,jul,sun,29.3,27,3.6,0,6.3 489 | 8,6,jul,tue,17.1,67,3.6,0,6.57 490 | 8,6,jun,sun,15.4,45,2.2,0,0 491 | 8,6,jun,wed,19.6,43,4.9,0,0 492 | 8,6,mar,fri,8.3,97,4,0.2,0 493 | 8,6,mar,fri,17.4,24,5.4,0,0 494 | 8,6,mar,sun,11.4,99,1.8,0,0 495 | 8,6,mar,sun,11.5,39,5.8,0,7.19 496 | 8,6,oct,mon,19.1,32,4,0,5.44 497 | 8,6,oct,wed,20.2,37,2.7,0,13.7 498 | 8,6,sep,fri,20.7,46,2.7,0,30.18 499 | 8,6,sep,mon,22.7,35,2.2,0,7.48 500 | 8,6,sep,mon,15.7,51,2.2,0,0 501 | 8,6,sep,mon,15.9,51,4.5,0,2.18 502 | 8,6,sep,sat,17.8,56,1.8,0,1.95 503 | 8,6,sep,thu,23.7,25,4.5,0,1.12 504 | 8,6,sep,tue,13.1,63,5.4,0,0 505 | 8,8,aug,wed,26.2,36,4.5,0,185.76 506 | 9,4,jul,mon,22.8,27,4.5,0,1.63 507 | 9,4,jul,sat,25.3,39,0.9,0,8 508 | 9,4,jun,sat,24.5,50,3.1,0,70.32 509 | 9,4,sep,tue,24.3,36,3.1,0,105.66 510 | 9,5,jun,wed,28,34,4.5,0,0 511 | 9,5,jun,wed,28,34,4.5,0,8.16 512 | 9,6,aug,thu,20.5,58,2.7,0,42.87 513 | 9,9,aug,fri,25,36,4,0,0 514 | 9,9,feb,fri,15.7,43,3.1,0,0 515 | 9,9,feb,thu,6.7,79,3.1,0,0 516 | 9,9,jul,sun,24.8,29,2.2,0,1.36 517 | 9,9,jul,thu,30.2,25,4.5,0,2.75 518 | 9,9,jul,tue,18,42,2.7,0,0.36 519 | -------------------------------------------------------------------------------- /ForestData.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/ForestData.xlsx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chinesetext.txt: -------------------------------------------------------------------------------- 1 | 秋登兰山寄张五 2 | 北山白云里,隐者自怡悦。 3 | 相望试登高,心随雁飞灭。 4 | 愁因薄暮起,兴是清秋发。 5 | 时见归村人,沙行渡头歇。 6 | 天边树若荠,江畔洲如月。 7 | 何当载酒来,共醉重阳节。 -------------------------------------------------------------------------------- /coursework.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 课程论文" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | " 请务必交到exer8文件夹下,**谢绝交到master下**\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请于12月30日前先在github上提交\n", 17 | "+ 请在元旦后提交纸质版,将本页面文件先打印为pdf格式,再去打印店付印\n", 18 | "+ 请将论文模板和本页面文件一起装订,前者放上面,本页面文件放下面\n", 19 | "+ 纸质版提交时间和地点请留意微信群通知" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "请写一下姓名和学号:\n", 27 | "+ 姓名 \n", 28 | "+ 学号" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "### 样本均值分布的统计试验" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "+ 请将CEPS.csv数据读入python\n", 43 | "+ 请从中随机抽取1000个数据\n", 44 | "+ 请根据问卷从数据中挑选两个连续型变量(likert量表可以近似看作连续变量)\n", 45 | "+ 计算这两个连续变量的均值\n", 46 | "+ 重复随机抽取—计算均值这个过程30次,得到两个变量30个样本均值\n", 47 | "+ 绘制这30个样本均值的直方图\n", 48 | "+ 计算均值的均值和标准误" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "### 回归分析" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "+ 请从CEPS.csv数据里挑选若干变量建立回归方程,要求至少三个自变量\n", 63 | " + 如,学生的学业成绩受认知水平、家庭收入的影响\n", 64 | " + 考虑因变量和自变量间的实质关系,变量间关系应该是有意义\n", 65 | " + 选择自变量时,注意变量的类型,如果是分类变量,需要进行编码\n", 66 | "+ 请报告回归方程的结果,需要包括:\n", 67 | " + 模型拟合指标\n", 68 | " + 模型的显著性检验结果\n", 69 | " + 变量的系数\n", 70 | " + 各系数的显著性检验结果\n", 71 | " + 对模型结果的解释\n", 72 | " " 73 | ] 74 | } 75 | ], 76 | "metadata": { 77 | "kernelspec": { 78 | "display_name": "Python 3", 79 | "language": "python", 80 | "name": "python3" 81 | }, 82 | "language_info": { 83 | "codemirror_mode": { 84 | "name": "ipython", 85 | "version": 3 86 | }, 87 | "file_extension": ".py", 88 | "mimetype": "text/x-python", 89 | "name": "python", 90 | "nbconvert_exporter": "python", 91 | "pygments_lexer": "ipython3", 92 | "version": "3.6.2" 93 | }, 94 | "toc": { 95 | "base_numbering": 1, 96 | "nav_menu": {}, 97 | "number_sections": true, 98 | "sideBar": true, 99 | "skip_h1_title": false, 100 | "title_cell": "Table of Contents", 101 | "title_sidebar": "Contents", 102 | "toc_cell": false, 103 | "toc_position": {}, 104 | "toc_section_display": true, 105 | "toc_window_display": false 106 | } 107 | }, 108 | "nbformat": 4, 109 | "nbformat_minor": 2 110 | } 111 | -------------------------------------------------------------------------------- /csv_mindex.csv: -------------------------------------------------------------------------------- 1 | key1,key2,value1,value2 2 | one,a,1,2 3 | one,b,3,4 4 | one,c,5,6 5 | one,d,7,8 6 | two,a,9,10 7 | two,b,11,12 8 | two,c,13,14 9 | two,d,15,16 10 | -------------------------------------------------------------------------------- /ex1.csv: -------------------------------------------------------------------------------- 1 | a,b,c,d,message 2 | 1,2,3,4,hello 3 | 5,6,7,8,world 4 | 9,10,11,12,foo -------------------------------------------------------------------------------- /ex1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/ex1.xlsx -------------------------------------------------------------------------------- /ex2.csv: -------------------------------------------------------------------------------- 1 | 1,2,3,4,hello 2 | 5,6,7,8,world 3 | 9,10,11,12,foo -------------------------------------------------------------------------------- /ex2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/ex2.xlsx -------------------------------------------------------------------------------- /ex3.txt: -------------------------------------------------------------------------------- 1 | A B C 2 | aaa -0.264438 -1.026059 -0.619500 3 | bbb 0.927272 0.302904 -0.032399 4 | ccc -0.264273 -0.386314 -0.217601 5 | ddd -0.871858 -0.348382 1.100491 6 | -------------------------------------------------------------------------------- /ex4.csv: -------------------------------------------------------------------------------- 1 | # hey! 2 | a,b,c,d,message 3 | # just wanted to make things more difficult for you 4 | # who reads CSV files with computers, anyway? 5 | 1,2,3,4,hello 6 | 5,6,7,8,world 7 | 9,10,11,12,foo -------------------------------------------------------------------------------- /ex5.csv: -------------------------------------------------------------------------------- 1 | something,a,b,c,d,message 2 | one,1,2,3,4,NA 3 | two,5,6,,8,world 4 | three,9,10,11,12,foo -------------------------------------------------------------------------------- /ex7.csv: -------------------------------------------------------------------------------- 1 | "a","b","c" 2 | "1","2","3" 3 | "1","2","3" 4 | -------------------------------------------------------------------------------- /example.json: -------------------------------------------------------------------------------- 1 | [{"a": 1, "b": 2, "c": 3}, 2 | {"a": 4, "b": 5, "c": 6}, 3 | {"a": 7, "b": 8, "c": 9}] 4 | -------------------------------------------------------------------------------- /exer1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第一次练习\n", 8 | "+ 把\"Hello World\"保存到一个变量里,并且print出来。\n", 9 | "+ 把一个文本信息保存到一个变量里,print出来,存一个新的文本信息到同一个变量里,print这个新信息。" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "collapsed": true 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "uni_name=' 江西财经大学 '\n", 21 | "print(uni_name)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "去掉上例中变量uni_name里的前后空格。" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "# 其他学院的同学可以将school改为自己学院名称\n", 40 | "\n", 41 | "school='统计学院'" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "+ 请将uni_name和school合并起来并打印出来。\n", 49 | "+ 请在uni_name和school之间加入一个制表符并打印出来,然后在uni_name和school间换一行再打印出来。" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": { 56 | "collapsed": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "height_yao = 226\n", 61 | "height_ye = 190" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "姚明的身高是226cm,叶莉的身高是190cm,请以文本和数字混排的形式,打印“叶莉比姚明低XXcm”,XX请在print中计算得到。" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "collapsed": true 76 | }, 77 | "outputs": [], 78 | "source": [] 79 | } 80 | ], 81 | "metadata": { 82 | "kernelspec": { 83 | "display_name": "Python 3", 84 | "language": "python", 85 | "name": "python3" 86 | }, 87 | "language_info": { 88 | "codemirror_mode": { 89 | "name": "ipython", 90 | "version": 3 91 | }, 92 | "file_extension": ".py", 93 | "mimetype": "text/x-python", 94 | "name": "python", 95 | "nbconvert_exporter": "python", 96 | "pygments_lexer": "ipython3", 97 | "version": "3.6.2" 98 | }, 99 | "toc": { 100 | "base_numbering": 1, 101 | "nav_menu": {}, 102 | "number_sections": true, 103 | "sideBar": true, 104 | "skip_h1_title": false, 105 | "title_cell": "Table of Contents", 106 | "title_sidebar": "Contents", 107 | "toc_cell": false, 108 | "toc_position": {}, 109 | "toc_section_display": true, 110 | "toc_window_display": false 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 2 115 | } 116 | -------------------------------------------------------------------------------- /exer2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第二次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### 食物和热量\n", 15 | "\n", 16 | "已知,以下食物每100g的千卡路里如下:\n", 17 | "\n", 18 | "小米粥 45 \n", 19 | "粗粮馒头 223 \n", 20 | "全麦面包 235 \n", 21 | "瘦猪肉 143 \n", 22 | "鸡翅 194 \n", 23 | "培根 181 \n", 24 | "火腿肠 212 \n", 25 | "\n", 26 | "建立一个空的字典,把上述键值对依此添加进去。 \n", 27 | "通过循环形式,显示,如“我吃了二两”+“小米粥”,“增加了”+“45”千卡路里。" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "### 运动和消耗\n", 35 | "常见三种运动的消耗热量表: \n", 36 | "慢走 (一小时4公里) 255 卡 \n", 37 | "慢跑 (一小时9公里) 655 卡 \n", 38 | "羽毛球(一小时) 440 卡 \n", 39 | "\n", 40 | "模仿课件3-dict_set中的cell[9]做个刷题,直到答对而且答完为止。" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 1, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Dictionary: A collection of key-value pairs.\n", 53 | "Function: A named set of instructions that defines a set of actions in Python.\n", 54 | "List: A collection of values that are not connected, but have an order.\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# 对dict来说,输出时不按任何顺序\n", 60 | "# 可以通过sorted()函数使结果有序输出\n", 61 | "python_words = {'list': 'A collection of values that are not connected, but have an order.',\n", 62 | " 'dictionary': 'A collection of key-value pairs.',\n", 63 | " 'function': 'A named set of instructions that defines a set of actions in Python.',\n", 64 | " }\n", 65 | "\n", 66 | "for word in sorted(python_words.keys()):\n", 67 | " print(\"%s: %s\" % (word.title(), python_words[word]))" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "### 江西最高山\n", 75 | "\n", 76 | "[江西最高的十座山]{http://jx.ifeng.com/a/20160628/4693979_0.shtml}\n", 77 | "\n", 78 | "请模仿上例,创建包含山名和海拔的dict,并按如下形式循环输出: \n", 79 | "“黄岗山海拔2157.8米”" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "### 为室友打一波广告\n", 87 | "请参照课件3-dict_set中的cell[15]“卖室友”吧。 \n", 88 | "第一层dict的key可自选,如身高、爱好、技能等等。\n", 89 | "并以以下形式循环输出: \n", 90 | "我知道的XXX,TA: \n", 91 | "身高:160 \n", 92 | "爱好:吸猫 \n", 93 | "技能:python \n", 94 | "\n", 95 | "\n", 96 | "\n" 97 | ] 98 | } 99 | ], 100 | "metadata": { 101 | "kernelspec": { 102 | "display_name": "Python 3", 103 | "language": "python", 104 | "name": "python3" 105 | }, 106 | "language_info": { 107 | "codemirror_mode": { 108 | "name": "ipython", 109 | "version": 3 110 | }, 111 | "file_extension": ".py", 112 | "mimetype": "text/x-python", 113 | "name": "python", 114 | "nbconvert_exporter": "python", 115 | "pygments_lexer": "ipython3", 116 | "version": "3.7.1" 117 | }, 118 | "toc": { 119 | "base_numbering": 1, 120 | "nav_menu": {}, 121 | "number_sections": true, 122 | "sideBar": true, 123 | "skip_h1_title": false, 124 | "title_cell": "Table of Contents", 125 | "title_sidebar": "Contents", 126 | "toc_cell": false, 127 | "toc_position": {}, 128 | "toc_section_display": true, 129 | "toc_window_display": true 130 | } 131 | }, 132 | "nbformat": 4, 133 | "nbformat_minor": 2 134 | } 135 | -------------------------------------------------------------------------------- /exer3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第三次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "+ 请务必交到exer3文件夹下,谢绝交到master下\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请在10月23日前提交。" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "请写一下姓名和学号:\n", 24 | "+ 姓名 \n", 25 | "+ 学号" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "### 请从read()函数指针的角度解读下面代码的结果" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 5, 38 | "metadata": { 39 | "scrolled": true 40 | }, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "一\n", 47 | "阵风吹过,龙宫的许多宝物被吹落在建邺城。\n", 48 | "双寿星日惊叹缘分神奇\n", 49 | "能够遇到你们\n", 50 | "就算花光所有运气也在所不惜\n", 51 | "希望后来的我们依旧快乐\n", 52 | "掉体脂过八高夜夜嗨唱四零七\n", 53 | "enmm...\n", 54 | "嘘~~(撒腿就跑并投掷两颗小心心)\n", 55 | "一个小时\n", 56 | "是姐姐姐夫直播吃螃蟹\n", 57 | "是弟弟直播吃 米果和石榴\n", 58 | "是我的健胃消食片\n", 59 | "祝我弟生日快乐 学习快乐 天天快乐\n", 60 | "(直播完还不是要补作业)\n", 61 | "你站立在小路的这一端,看着他逐渐消失在小路转弯的地方,而且,他用背影默默告诉你:不必追。\n", 62 | "\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "f = open(\"exer3.txt\",\"r\") #opens file with name of \"test.txt\"\n", 68 | "print(f.read(1))\n", 69 | "print(f.read())" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "**解读请点开此cell后,写下面:**\n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "### 请从readline()函数指针的角度解读下面代码的结果" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 6, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "一阵风吹过,龙宫的许多宝物被吹落在建邺城。\n", 104 | "\n", 105 | "双寿星日惊叹缘分神奇\n", 106 | "\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "f = open(\"exer3.txt\",\"r\") #opens file with name of \"test.txt\"\n", 112 | "print(f.readline())\n", 113 | "print(f.readline())" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "**解读请点开此cell后,写下面:**\n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "### 请将上面的代码扩充为循环,直至显示文本全部内容。" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "### 下面的代码实现了把exer3的内容放到myList里,但是里面出现了很多换行符,请修改下代码使得myList里的内容没有换行符" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 7, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "['一阵风吹过,龙宫的许多宝物被吹落在建邺城。\\n', '双寿星日惊叹缘分神奇\\n', '能够遇到你们\\n', '就算花光所有运气也在所不惜\\n', '希望后来的我们依旧快乐\\n', '掉体脂过八高夜夜嗨唱四零七\\n', 'enmm...\\n', '嘘~~(撒腿就跑并投掷两颗小心心)\\n', '一个小时\\n', '是姐姐姐夫直播吃螃蟹\\n', '是弟弟直播吃 米果和石榴\\n', '是我的健胃消食片\\n', '祝我弟生日快乐 学习快乐 天天快乐\\n', '(直播完还不是要补作业)\\n', '你站立在小路的这一端,看着他逐渐消失在小路转弯的地方,而且,他用背影默默告诉你:不必追。\\n']\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "f = open(\"exer3.txt\",\"r\") #opens file with name of \"test.txt\"\n", 160 | "myList = []\n", 161 | "for line in f:\n", 162 | " myList.append(line)\n", 163 | "print(myList)" 164 | ] 165 | } 166 | ], 167 | "metadata": { 168 | "kernelspec": { 169 | "display_name": "Python 3", 170 | "language": "python", 171 | "name": "python3" 172 | }, 173 | "language_info": { 174 | "codemirror_mode": { 175 | "name": "ipython", 176 | "version": 3 177 | }, 178 | "file_extension": ".py", 179 | "mimetype": "text/x-python", 180 | "name": "python", 181 | "nbconvert_exporter": "python", 182 | "pygments_lexer": "ipython3", 183 | "version": "3.6.6" 184 | }, 185 | "toc": { 186 | "base_numbering": 1, 187 | "nav_menu": {}, 188 | "number_sections": true, 189 | "sideBar": true, 190 | "skip_h1_title": false, 191 | "title_cell": "Table of Contents", 192 | "title_sidebar": "Contents", 193 | "toc_cell": false, 194 | "toc_position": {}, 195 | "toc_section_display": true, 196 | "toc_window_display": true 197 | } 198 | }, 199 | "nbformat": 4, 200 | "nbformat_minor": 2 201 | } 202 | -------------------------------------------------------------------------------- /exer3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/exer3.txt -------------------------------------------------------------------------------- /exer4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第四次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "+ 请务必交到exer4文件夹下,谢绝交到master下\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请在10月30日前提交。" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "请写一下姓名和学号:\n", 24 | "+ 姓名 \n", 25 | "+ 学号" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "#### 题目一\n", 33 | "一般的歌,分为主歌和副歌部分。副歌有重复,对比两大功能。这就是A-B的基本曲式形式结构。 \n", 34 | "请找一首你的主打歌,把歌词打印出来,重复的副歌部分,请写一个函数,调用函数打印出来。" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "#### 题目二\n", 42 | "请写一个函数,能够计算均值、样本方差和n(自己写公式哦)。\n", 43 | "每次输入十个以上的数字,能够输出上述三个统计量。\n", 44 | "至少调用两次。" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "#### 题目三\n", 52 | "刚才那个函数,默认的是输出均值、样本方差和n,请在后面添加一个关键词参数,让这个函数可以选择输出样本标准差或方差。" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "#### 题目四\n", 60 | "刚才那个函数,请再增加三个关键词参数,让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [] 69 | } 70 | ], 71 | "metadata": { 72 | "kernelspec": { 73 | "display_name": "Python 3", 74 | "language": "python", 75 | "name": "python3" 76 | }, 77 | "language_info": { 78 | "codemirror_mode": { 79 | "name": "ipython", 80 | "version": 3 81 | }, 82 | "file_extension": ".py", 83 | "mimetype": "text/x-python", 84 | "name": "python", 85 | "nbconvert_exporter": "python", 86 | "pygments_lexer": "ipython3", 87 | "version": "3.6.6" 88 | } 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 2 92 | } 93 | -------------------------------------------------------------------------------- /exer5.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第五次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "+ 请务必交到exer5文件夹下,**谢绝交到master下**\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请在11月7日前提交。" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "请写一下姓名和学号:\n", 24 | "+ 姓名 \n", 25 | "+ 学号" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "#### 题目一、贫困户模型\n", 33 | "+ 创建一个类,包含贫困户的义务教育保障、住房安全、饮水安全、肉蛋奶豆的四个属性\n", 34 | "+ 包含一个是否贫困的预测,如果四个属性有两个以上没有保障(>2)则输出为贫困户\n", 35 | "+ 对贫困户,采取相应措施(输入参数)对其进行帮扶,使其脱贫\n", 36 | "+ 至少生成三个实例\n" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "#### 题目二: 学生信息\n", 44 | "+ 创建一个类,包含姓名、分数、睡眠时间三个属性\n", 45 | "+ 包含一个胖瘦的预测,如果分数>90,且睡眠时间少于6小时,输出“BMI可能偏大”,否则输出“体重正常”\n", 46 | "+ 为使得标准(90分、6小时)可以调整,标准应设为输入的参数\n", 47 | "+ 至少生成三个实例" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "#### 题目三:“跑步社”成员类\n", 55 | "+ 创建一个“跑步社”成员类,以学生信息类为父类\n", 56 | "+ 添加一个属性为跑步\n", 57 | "+ 如果跑步时间大于30分钟,如果之前预测为“BMI可能偏大”,则输出为“趋向正常”\n", 58 | "+ 至少生成三个实例" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [] 67 | } 68 | ], 69 | "metadata": { 70 | "kernelspec": { 71 | "display_name": "Python 3", 72 | "language": "python", 73 | "name": "python3" 74 | }, 75 | "language_info": { 76 | "codemirror_mode": { 77 | "name": "ipython", 78 | "version": 3 79 | }, 80 | "file_extension": ".py", 81 | "mimetype": "text/x-python", 82 | "name": "python", 83 | "nbconvert_exporter": "python", 84 | "pygments_lexer": "ipython3", 85 | "version": "3.6.6" 86 | } 87 | }, 88 | "nbformat": 4, 89 | "nbformat_minor": 2 90 | } 91 | -------------------------------------------------------------------------------- /exer6.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第六次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "+ 请务必交到exer6文件夹下,**谢绝交到master下**\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请在12月4日前提交。" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "请写一下姓名和学号:\n", 24 | "+ 姓名 \n", 25 | "+ 学号" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "### 请建立一个数据框,列出你在双十一购买的至少五样物品。\n", 33 | "用它们的名称作为index的label,在列里列出这些物品(数据可以是虚拟的)的:\n", 34 | "+ 价格\n", 35 | "+ 购买的数量\n", 36 | "+ 收到的时间(类似1113即可,表示11月13日收到)\n", 37 | "+ 你的评价(从1到5,1表示很不好,5表示很好)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "#### 用index的label读取某一个物品数据" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "#### 选择价格>200的物品" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "#### 挑选其中和学习有关的物品,构成一个子集" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "#### 读取评价那列的数据" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "#### 根据label对数据框重新排序,按照对你的迫切程度" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "#### 生成一个series,记录这些物品的快递费,然后加到价格上" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "#### 按照价格从高到底排序" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "#### 按照收到的时间从低到高排序" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "#### 得到各样物品评价的排名" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "#### 计算一下这些物品的总花费、最大值、最小值和平均值" 108 | ] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.6.2" 128 | }, 129 | "toc": { 130 | "base_numbering": 1, 131 | "nav_menu": {}, 132 | "number_sections": true, 133 | "sideBar": true, 134 | "skip_h1_title": false, 135 | "title_cell": "Table of Contents", 136 | "title_sidebar": "Contents", 137 | "toc_cell": false, 138 | "toc_position": {}, 139 | "toc_section_display": true, 140 | "toc_window_display": false 141 | } 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 2 145 | } 146 | -------------------------------------------------------------------------------- /exer7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## 第七次练习" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "+ 请务必交到exer7文件夹下,**谢绝交到master下**\n", 15 | "+ 请不要改动任何文件,拜托\n", 16 | "+ 请在12月20日前提交。" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "请写一下姓名和学号:\n", 24 | "+ 姓名 \n", 25 | "+ 学号" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 1, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "import numpy as np\n", 37 | "import pandas as pd" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": { 44 | "collapsed": true 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "请参考下面命令将CEPS.csv数据读入python" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 7, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "name": "stderr", 58 | "output_type": "stream", 59 | "text": [ 60 | "C:\\Users\\Administrator\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2698: DtypeWarning: Columns (20,22,23,25,28,29,39,49,74,124,125,126,127,128,129,130,131,138,140,141,147,160,161,162,165,170,174,175,176,177,179,180,181,182,183,184,188,191,194,195,196,199,221,222,223,224,251,252,254,289,290,294,295,296) have mixed types. Specify dtype option on import or set low_memory=False.\n", 61 | " interactivity=interactivity, compiler=compiler, result=result)\n" 62 | ] 63 | }, 64 | { 65 | "data": { 66 | "text/html": [ 67 | "
\n", 68 | "\n", 81 | "\n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | "
idsclsidsschidsctyidsframesubsamplesweightfallgrade9stcog...steco_3cstonlystsibstsibrankstmedustfedustprhedustfdrunkstprfightstprrel
0111133218.7388920011...31333112
1211133216.5182340017...21858112
2311133216.5182340012...2213333111
3411133218.7388920010...21677112
4511133217.5530400010...31788112
\n", 231 | "

5 rows × 300 columns

\n", 232 | "
" 233 | ], 234 | "text/plain": [ 235 | " ids clsids schids ctyids frame subsample sweight fall grade9 \\\n", 236 | "0 1 1 1 1 3 3 218.738892 0 0 \n", 237 | "1 2 1 1 1 3 3 216.518234 0 0 \n", 238 | "2 3 1 1 1 3 3 216.518234 0 0 \n", 239 | "3 4 1 1 1 3 3 218.738892 0 0 \n", 240 | "4 5 1 1 1 3 3 217.553040 0 0 \n", 241 | "\n", 242 | " stcog ... steco_3c stonly stsib stsibrank stmedu stfedu stprhedu \\\n", 243 | "0 11 ... 3 1 3 3 3 \n", 244 | "1 17 ... 2 1 8 5 8 \n", 245 | "2 12 ... 2 2 1 3 3 3 3 \n", 246 | "3 10 ... 2 1 6 7 7 \n", 247 | "4 10 ... 3 1 7 8 8 \n", 248 | "\n", 249 | " stfdrunk stprfight stprrel \n", 250 | "0 1 1 2 \n", 251 | "1 1 1 2 \n", 252 | "2 1 1 1 \n", 253 | "3 1 1 2 \n", 254 | "4 1 1 2 \n", 255 | "\n", 256 | "[5 rows x 300 columns]" 257 | ] 258 | }, 259 | "execution_count": 7, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "df = pd.read_csv('CEPS.csv',encoding='gb2312')\n", 266 | "df.head()\n" 267 | ] 268 | }, 269 | { 270 | "cell_type": "markdown", 271 | "metadata": {}, 272 | "source": [ 273 | "下面的图都至少需要在图上标注:\n", 274 | "+ 图标题\n", 275 | "+ x轴标题\n", 276 | "+ y轴标题\n", 277 | "+ 适当修改x轴或者y轴的刻度及标签,使之清晰美观\n", 278 | "+ 根据需要添加图例" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": {}, 284 | "source": [ 285 | "### 散点图\n", 286 | "反映期中考试标准化成绩语文(stdchn)和期中考试标准化成绩数学(stdmat)的相关关系" 287 | ] 288 | }, 289 | { 290 | "cell_type": "markdown", 291 | "metadata": {}, 292 | "source": [ 293 | "### 饼图\n", 294 | "对问题“你是独生子女吗”(b01)的回答有“是”和“否”两种回答,相应的数字分别是1和2。请画一个饼图反映二者的比例。" 295 | ] 296 | }, 297 | { 298 | "cell_type": "markdown", 299 | "metadata": {}, 300 | "source": [ 301 | "### 直方图\n", 302 | "反映变量“每天晚上睡多长时间-小时”(b18a)的分布情况。" 303 | ] 304 | }, 305 | { 306 | "attachments": {}, 307 | "cell_type": "markdown", 308 | "metadata": {}, 309 | "source": [ 310 | "### 柱图\n", 311 | "反映变量\"你妈妈是做什么工作的\"(b08a)的职业分布情况,数字和编码关系如下:\n", 312 | "\n", 313 | "+ 1\t国家机关事业单位领导与工作人员\n", 314 | "+ 2\t企业/公司中高级管理人员\n", 315 | "+ 3\t教师、工程师、医生、律师\n", 316 | "+ 4\t技术工人(包括司机)\n", 317 | "+ 5\t生产与制造业一般职工\n", 318 | "+ 6\t商业与服务业一般职工\n", 319 | "+ 7\t个体户\n", 320 | "+ 8\t农民\n", 321 | "+ 9 无业、失业、下岗\n" 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": null, 327 | "metadata": { 328 | "collapsed": true 329 | }, 330 | "outputs": [], 331 | "source": [] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": null, 336 | "metadata": { 337 | "collapsed": true 338 | }, 339 | "outputs": [], 340 | "source": [] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": null, 345 | "metadata": { 346 | "collapsed": true 347 | }, 348 | "outputs": [], 349 | "source": [] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": null, 354 | "metadata": { 355 | "collapsed": true 356 | }, 357 | "outputs": [], 358 | "source": [] 359 | }, 360 | { 361 | "cell_type": "code", 362 | "execution_count": null, 363 | "metadata": { 364 | "collapsed": true 365 | }, 366 | "outputs": [], 367 | "source": [] 368 | } 369 | ], 370 | "metadata": { 371 | "kernelspec": { 372 | "display_name": "Python 3", 373 | "language": "python", 374 | "name": "python3" 375 | }, 376 | "language_info": { 377 | "codemirror_mode": { 378 | "name": "ipython", 379 | "version": 3 380 | }, 381 | "file_extension": ".py", 382 | "mimetype": "text/x-python", 383 | "name": "python", 384 | "nbconvert_exporter": "python", 385 | "pygments_lexer": "ipython3", 386 | "version": "3.6.2" 387 | }, 388 | "toc": { 389 | "base_numbering": 1, 390 | "nav_menu": {}, 391 | "number_sections": true, 392 | "sideBar": true, 393 | "skip_h1_title": false, 394 | "title_cell": "Table of Contents", 395 | "title_sidebar": "Contents", 396 | "toc_cell": false, 397 | "toc_position": {}, 398 | "toc_section_display": true, 399 | "toc_window_display": false 400 | } 401 | }, 402 | "nbformat": 4, 403 | "nbformat_minor": 2 404 | } 405 | -------------------------------------------------------------------------------- /exfriend.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/exfriend.jpg -------------------------------------------------------------------------------- /movies.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/movies.json -------------------------------------------------------------------------------- /out.csv: -------------------------------------------------------------------------------- 1 | a,b,c 2 | 1,2,3.0 3 | 5,6, 4 | 9,10,11.0 5 | -------------------------------------------------------------------------------- /out.txt: -------------------------------------------------------------------------------- 1 | |something|a|b|c|d|message 2 | 0|one|1|2|3.0|4| 3 | 1|two|5|6||8|world 4 | 2|three|9|10|11.0|12|foo 5 | -------------------------------------------------------------------------------- /pi_digits.txt: -------------------------------------------------------------------------------- 1 | 3.1415926535 2 | 8979323846 3 | 2643383279 4 | -------------------------------------------------------------------------------- /pipaxing.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fanofmeasurement/python-LEC/491e972c71508274ed3e6be9b374df16dcf43b8d/pipaxing.txt -------------------------------------------------------------------------------- /programming.txt: -------------------------------------------------------------------------------- 1 | 3.1415926535 2 | 8979323846 3 | 2643383279 4 | I also love finding meaning in large datasets. 5 | I also love creating apps that can run in a browser. 6 | I also love finding meaning in large datasets. 7 | I also love creating apps that can run in a browser. 8 | I also love finding meaning in large datasets. 9 | I also love creating apps that can run in a browser. 10 | -------------------------------------------------------------------------------- /tseries.csv: -------------------------------------------------------------------------------- 1 | 2000-01-01,0 2 | 2000-01-02,1 3 | 2000-01-03,2 4 | 2000-01-04,3 5 | 2000-01-05,4 6 | 2000-01-06,5 7 | 2000-01-07,6 8 | --------------------------------------------------------------------------------