From c92e633877d9bc4fdb8f45df1ef243afc75713de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Wed, 31 May 2023 22:18:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=8A=A0=E5=85=A5=E9=BB=91=E9=A9=AC?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_bot_opencat.py | 0 .../01_\346\263\250\351\207\212.py" | 6 + .../02_\345\217\230\351\207\217.py" | 8 + ...04\345\255\227\351\235\242\351\207\217.py" | 7 + ...55\347\232\204\346\263\250\351\207\212.py" | 21 + ...55\347\232\204\345\217\230\351\207\217.py" | 32 + ...60\346\215\256\347\261\273\345\236\213.py" | 19 + ...73\345\236\213\350\275\254\346\215\242.py" | 25 + ...04\346\240\207\350\257\206\347\254\246.py" | 21 + ...46\344\270\262\346\213\274\346\216\245.py" | 12 + ...62\346\240\274\345\274\217\345\214\226.py" | 23 + ...03\350\277\220\347\256\227\347\254\246.py" | 34 + ...55\347\273\203\344\271\240\351\242\230.py" | 12 + ...72\347\241\200\346\240\274\345\274\217.py" | 10 + ...27\347\273\203\344\271\240\351\242\230.py" | 15 + ...45\347\232\204\344\275\277\347\224\250.py" | 13 + ...27\347\273\203\344\271\240\351\242\230.py" | 18 + ...45\347\232\204\344\275\277\347\224\250.py" | 17 + ...45\347\232\204\345\265\214\345\245\227.py" | 38 + ...36\346\210\230\346\241\210\344\276\213.py" | 29 + ...6\261\2021-100\347\232\204\345\222\214.py" | 10 + ...72\347\241\200\350\257\255\346\263\225.py" | 7 + ...3-\347\214\234\346\225\260\345\255\227.py" | 27 + ...14\345\245\227\345\272\224\347\224\250.py" | 22 + ...35\344\271\230\346\263\225\350\241\250.py" | 21 + ...0\346\234\211\345\207\240\344\270\252a.py" | 23 + ...72\347\241\200\350\257\255\346\263\225.py" | 13 + .../06_range\350\257\255\345\217\245.py" | 20 + ...17\344\275\234\347\224\250\345\237\237.py" | 9 + ...35\344\271\230\346\263\225\350\241\250.py" | 14 + ...14\345\245\227\344\275\277\347\224\250.py" | 20 + ...52\347\216\257\344\270\255\346\226\255.py" | 51 + ...3-\345\217\221\345\267\245\350\265\204.py" | 17 + .../test.py" | 6 + ...53\351\200\237\344\275\223\351\252\214.py" | 9 + ...75\346\225\260\345\256\232\344\271\211.py" | 13 + ...03\344\271\240\346\241\210\344\276\213.py" | 11 + ...50\347\232\204\345\276\252\347\216\257.py" | 39 + ...60\347\232\204\345\217\202\346\225\260.py" | 11 + ...03\344\271\240\346\241\210\344\276\213.py" | 15 + ...32\344\271\211\350\257\255\346\263\225.py" | 18 + "05_\345\207\275\346\225\260/07_None.py" | 35 + ...64\346\230\216\346\226\207\346\241\243.py" | 18 + ...14\345\245\227\350\260\203\347\224\250.py" | 17 + ...04\344\275\234\347\224\250\345\237\237.py" | 55 + ...74\345\220\210\346\241\210\344\276\213.py" | 62 + "05_\345\207\275\346\225\260/test.py" | 17 + ...32\350\277\224\345\233\236\345\200\274.py" | 14 + ...77\347\224\250\345\275\242\345\274\217.py" | 31 + ...02\346\225\260\344\274\240\351\200\222.py" | 15 + ...77\345\220\215\345\207\275\346\225\260.py" | 18 + .../test.py" | 8 + .../01_list\345\210\227\350\241\250.py" | 36 + ...70\347\224\250\346\223\215\344\275\234.py" | 57 + ...76\345\220\216\347\273\203\344\271\240.py" | 24 + ...50\347\232\204\345\276\252\347\216\257.py" | 23 + .../05_tuple\345\205\203\347\273\204.py" | 55 + ...6_\345\255\227\347\254\246\344\270\262.py" | 40 + ...76\345\220\216\347\273\203\344\271\240.py" | 14 + ...27\345\222\214\345\210\207\347\211\207.py" | 37 + ...76\345\220\216\347\273\203\344\271\240.py" | 15 + .../10_\351\233\206\345\220\210.py" | 64 + ...76\345\220\216\347\273\203\344\271\240.py" | 19 + .../12_\345\255\227\345\205\270.py" | 47 + ...70\347\224\250\346\223\215\344\275\234.py" | 37 + ...76\345\220\216\347\273\203\344\271\240.py" | 50 + ...32\347\224\250\345\212\237\350\203\275.py" | 70 + ...47\345\260\217\346\257\224\350\276\203.py" | 12 + .../test.py" | 12 + ...66\347\232\204\350\257\273\345\217\226.py" | 38 + ...76\345\220\216\347\273\203\344\271\240.py" | 22 + ...66\347\232\204\345\206\231\345\205\245.py" | 21 + ...75\345\212\240\345\206\231\345\205\245.py" | 18 + ...74\345\220\210\346\241\210\344\276\213.py" | 22 + ...70\347\232\204\345\207\272\347\216\260.py" | 6 + ...70\347\232\204\346\215\225\350\216\267.py" | 37 + ...70\347\232\204\344\274\240\351\200\222.py" | 24 + ...27\347\232\204\345\257\274\345\205\245.py" | 46 + ...32\344\271\211\346\250\241\345\235\227.py" | 21 + .../06_\345\214\205.py" | 26 + ...10\344\276\213\347\273\203\344\271\240.py" | 14 + ...41\345\235\227\345\212\237\350\203\275.py" | 18 + ...60\346\215\256\346\240\274\345\274\217.py" | 24 + ...72\347\241\200\345\205\245\351\227\250.py" | 23 + ...77\345\233\276\345\274\200\345\217\221.py" | 68 + ...72\346\234\254\344\275\277\347\224\250.py" | 34 + ...60\345\233\276\345\274\200\345\217\221.py" | 47 + ...60\345\233\276\345\274\200\345\217\221.py" | 50 + ...66\345\233\276\345\274\200\345\217\221.py" | 19 + ...66\345\233\276\345\274\200\345\217\221.py" | 40 + ...47\232\204sort\346\226\271\346\263\225.py" | 17 + ...66\345\233\276\345\274\200\345\217\221.py" | 72 + ...345\211\2158\345\233\275\345\256\266.html" | 9546 +++++++++++++++++ .../test.py" | 90 + ...\346\203\205\345\234\260\345\233\276.html" | 309 + ...\346\237\261\347\212\266\345\233\276.html" | 521 + ...\346\237\261\347\212\266\345\233\276.html" | 159 + ...\346\203\205\345\234\260\345\233\276.html" | 257 + ...20\345\221\230\346\226\271\346\263\225.py" | 23 + ...73\345\222\214\345\257\271\350\261\241.py" | 30 + ...04\351\200\240\346\226\271\346\263\225.py" | 19 + ...05\347\275\256\346\226\271\346\263\225.py" | 37 + .../06_\345\260\201\350\243\205.py" | 24 + ...16\347\273\203\344\271\240\351\242\230.py" | 27 + ...72\347\241\200\350\257\255\346\263\225.py" | 61 + ...66\347\261\273\346\210\220\345\221\230.py" | 34 + ...0\350\247\243_\345\217\230\351\207\217.py" | 35 + ...60\345\222\214\346\226\271\346\263\225.py" | 13 + ...24\345\220\210\347\261\273\345\236\213.py" | 11 + .../13_\345\244\232\346\200\201.py" | 80 + .../data_define.py" | 16 + .../file_define.py" | 66 + .../main.py" | 44 + ...\346\237\261\347\212\266\345\233\276.html" | 257 + .../main.py" | 11 + .../01_pymysql\345\205\245\351\227\250.py" | 23 + ...60\346\215\256\346\217\222\345\205\245.py" | 25 + 12_sql/data_define.py | 22 + 12_sql/file_define.py | 66 + 12_sql/main.py | 39 + 12_sql/main2.py | 27 + ...72\347\241\200\345\207\206\345\244\207.py" | 15 + ...60\346\215\256\350\276\223\345\205\245.py" | 27 + ...47\256\227_map\346\226\271\346\263\225.py" | 23 + ...56\227_flatMap\346\226\271\346\263\225.py" | 15 + ...27_reduceByKey\346\226\271\346\263\225.py" | 14 + ...3\344\271\240\346\241\210\344\276\2131.py" | 21 + ...256\227_filter\346\226\271\346\263\225.py" | 16 + ...6\227_distinct\346\226\271\346\263\225.py" | 16 + ...256\227_sortBy\346\226\271\346\263\225.py" | 23 + ...3\344\271\240\346\241\210\344\276\2132.py" | 42 + ...\270\272Python\345\257\271\350\261\241.py" | 29 + ...72\345\210\260\346\226\207\344\273\266.py" | 26 + ...74\345\220\210\346\241\210\344\276\213.py" | 59 + ...06\347\276\244\350\277\220\350\241\214.py" | 58 + .../01_\351\227\255\345\214\205.py" | 57 + ...2_\350\243\205\351\245\260\345\231\250.py" | 44 + .../str_tools_py.py" | 11 + .../test.py" | 7 + .../test2.py" | 7 + ...25\344\276\213\346\265\213\350\257\225.py" | 11 + ...45\345\216\202\346\250\241\345\274\217.py" | 32 + ...77\347\250\213\347\274\226\347\250\213.py" | 26 + ...41\347\253\257\345\274\200\345\217\221.py" | 36 + ...67\347\253\257\345\274\200\345\217\221.py" | 20 + ...72\347\241\200\345\214\271\351\205\215.py" | 19 + ...27\347\254\246\345\214\271\351\205\215.py" | 26 + .../10_\351\200\222\345\275\222.py" | 46 + data/input/Audio.wav | Bin 0 -> 7476 bytes data/input/order.csv | 10 + data/input/wordcount.txt | 12 + my_package/__init__.py | 1 + my_package/my_module1.py | 8 + my_package/my_module2.py | 7 + my_utils/__init__.py | 0 my_utils/file_util.py | 40 + my_utils/str_util.py | 28 + test.py | 33 +- test_mysql.py | 19 + tmp/my.py | 29 + tmp/t2.py | 10 + tmp/test.py | 29 + tmp/test2.py | 18 + 163 files changed, 15175 insertions(+), 12 deletions(-) rename chat_bot_opencat.py => 00-chartgpt/chat_bot_opencat.py (100%) create mode 100644 "01_\344\275\240\345\245\275Python/01_\346\263\250\351\207\212.py" create mode 100644 "01_\344\275\240\345\245\275Python/02_\345\217\230\351\207\217.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/01_Python\344\270\255\347\232\204\345\255\227\351\235\242\351\207\217.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/02_Python\344\270\255\347\232\204\346\263\250\351\207\212.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/03_Python\344\270\255\347\232\204\345\217\230\351\207\217.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/04_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213\350\275\254\346\215\242.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\240\207\350\257\206\347\254\246.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/06_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\213\274\346\216\245.py" create mode 100644 "02_Python\345\205\245\351\227\250\350\257\255\346\263\225/07_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\345\214\226.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/01_\345\270\203\345\260\224\347\261\273\345\236\213\345\222\214\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_2_\346\210\220\345\271\264\344\272\272\345\210\244\346\226\255\347\273\203\344\271\240\351\242\230.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_if\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\237\272\347\241\200\346\240\274\345\274\217.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_2_\346\210\221\350\246\201\344\271\260\347\245\250\345\220\227\347\273\203\344\271\240\351\242\230.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_if else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_2_\347\214\234\347\214\234\345\277\203\351\207\214\346\225\260\345\255\227\347\273\203\344\271\240\351\242\230.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_if_elif_else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/05_\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\265\214\345\245\227.py" create mode 100644 "03_Python\345\210\244\346\226\255\350\257\255\345\217\245/06_\345\210\244\346\226\255\350\257\255\345\217\245\345\256\236\346\210\230\346\241\210\344\276\213.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_2_while\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230_\346\261\2021-100\347\232\204\345\222\214.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/02_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\346\241\210\344\276\213-\347\214\234\346\225\260\345\255\227.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/03_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\345\272\224\347\224\250.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/04_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\346\241\210\344\276\213-\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_2_for\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230-\346\225\260\344\270\200\346\225\260\346\234\211\345\207\240\344\270\252a.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_for\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/06_range\350\257\255\345\217\245.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/07_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_2_for\345\276\252\347\216\257\346\211\223\345\215\260\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_for\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\344\275\277\347\224\250.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\276\252\347\216\257\344\270\255\346\226\255.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/10_\345\276\252\347\216\257\347\273\274\345\220\210\346\241\210\344\276\213-\345\217\221\345\267\245\350\265\204.py" create mode 100644 "04_Python\345\276\252\347\216\257\350\257\255\345\217\245/test.py" create mode 100644 "05_\345\207\275\346\225\260/01_\345\207\275\346\225\260\345\277\253\351\200\237\344\275\223\351\252\214.py" create mode 100644 "05_\345\207\275\346\225\260/02_\345\207\275\346\225\260\345\256\232\344\271\211.py" create mode 100644 "05_\345\207\275\346\225\260/03_\345\207\275\346\225\260\345\237\272\347\241\200\345\256\232\344\271\211\347\273\203\344\271\240\346\241\210\344\276\213.py" create mode 100644 "05_\345\207\275\346\225\260/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" create mode 100644 "05_\345\207\275\346\225\260/04_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260.py" create mode 100644 "05_\345\207\275\346\225\260/05_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260\347\273\203\344\271\240\346\241\210\344\276\213.py" create mode 100644 "05_\345\207\275\346\225\260/06_\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236\345\200\274\345\256\232\344\271\211\350\257\255\346\263\225.py" create mode 100644 "05_\345\207\275\346\225\260/07_None.py" create mode 100644 "05_\345\207\275\346\225\260/08_\345\207\275\346\225\260\347\232\204\350\257\264\346\230\216\346\226\207\346\241\243.py" create mode 100644 "05_\345\207\275\346\225\260/09_\345\207\275\346\225\260\347\232\204\345\265\214\345\245\227\350\260\203\347\224\250.py" create mode 100644 "05_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" create mode 100644 "05_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" create mode 100644 "05_\345\207\275\346\225\260/test.py" create mode 100644 "06_\345\207\275\346\225\260\350\277\233\351\230\266/01_\345\207\275\346\225\260\347\232\204\345\244\232\350\277\224\345\233\236\345\200\274.py" create mode 100644 "06_\345\207\275\346\225\260\350\277\233\351\230\266/02_\345\207\275\346\225\260\345\217\202\346\225\260\347\232\204\345\244\232\347\247\215\344\275\277\347\224\250\345\275\242\345\274\217.py" create mode 100644 "06_\345\207\275\346\225\260\350\277\233\351\230\266/03_\345\207\275\346\225\260\344\275\234\344\270\272\345\217\202\346\225\260\344\274\240\351\200\222.py" create mode 100644 "06_\345\207\275\346\225\260\350\277\233\351\230\266/04_lambda\345\214\277\345\220\215\345\207\275\346\225\260.py" create mode 100644 "06_\345\207\275\346\225\260\350\277\233\351\230\266/test.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/01_list\345\210\227\350\241\250.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/03_list\345\210\227\350\241\250\345\270\270\347\224\250\346\223\215\344\275\234\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/05_tuple\345\205\203\347\273\204.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/07_\345\255\227\347\254\246\344\270\262\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/09_\345\272\217\345\210\227\345\210\207\347\211\207\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/10_\351\233\206\345\220\210.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/11_\351\233\206\345\220\210\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/12_\345\255\227\345\205\270.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/13_\345\255\227\345\205\270\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/14_\345\255\227\345\205\270\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/15_\346\225\260\346\215\256\345\256\271\345\231\250\351\200\232\347\224\250\345\212\237\350\203\275.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/16_\345\255\227\347\254\246\344\270\262\345\244\247\345\260\217\346\257\224\350\276\203.py" create mode 100644 "07_\346\225\260\346\215\256\345\256\271\345\231\250/test.py" create mode 100644 "08_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" create mode 100644 "08_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" create mode 100644 "08_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" create mode 100644 "08_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" create mode 100644 "08_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/01_\346\274\224\347\244\272\345\274\202\345\270\270\347\232\204\345\207\272\347\216\260.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/02_\345\274\202\345\270\270\347\232\204\346\215\225\350\216\267.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/04_\346\250\241\345\235\227\347\232\204\345\257\274\345\205\245.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/05_\350\207\252\345\256\232\344\271\211\346\250\241\345\235\227.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" create mode 100644 "09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/01_json\346\225\260\346\215\256\346\240\274\345\274\217.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/02_pyecharts\345\237\272\347\241\200\345\205\245\351\227\250.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/03_\346\212\230\347\272\277\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/04_\345\234\260\345\233\276\345\217\257\350\247\206\345\214\226\347\232\204\345\237\272\346\234\254\344\275\277\347\224\250.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/05_\345\205\250\345\233\275\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/06_\347\234\201\347\272\247\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/07_\345\237\272\347\241\200\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/08_\345\237\272\347\241\200\346\227\266\351\227\264\347\272\277\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/09_\346\213\223\345\261\225\347\237\245\350\257\206\347\202\271-\345\210\227\350\241\250\347\232\204sort\346\226\271\346\263\225.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/10_GDP\345\212\250\346\200\201\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/1960-2019\345\205\250\347\220\203GDP\345\211\2158\345\233\275\345\256\266.html" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/test.py" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\345\205\250\345\233\275\347\226\253\346\203\205\345\234\260\345\233\276.html" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\345\237\272\347\241\200\346\227\266\351\227\264\347\272\277\346\237\261\347\212\266\345\233\276.html" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\345\237\272\347\241\200\346\237\261\347\212\266\345\233\276.html" create mode 100644 "10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\346\262\263\345\215\227\347\234\201\347\226\253\346\203\205\345\234\260\345\233\276.html" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/02_\346\210\220\345\221\230\346\226\271\346\263\225.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/03_\347\261\273\345\222\214\345\257\271\350\261\241.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/04_\346\236\204\351\200\240\346\226\271\346\263\225.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/05_\345\205\266\345\256\203\345\206\205\347\275\256\346\226\271\346\263\225.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/06_\345\260\201\350\243\205.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/07_\345\260\201\350\243\205\350\257\276\345\220\216\347\273\203\344\271\240\351\242\230.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/08_\347\273\247\346\211\277\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/09_\347\273\247\346\211\277_\345\244\215\345\206\231\345\222\214\344\275\277\347\224\250\347\210\266\347\261\273\346\210\220\345\221\230.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/10_\347\261\273\345\236\213\346\263\250\350\247\243_\345\217\230\351\207\217.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/11_\347\261\273\345\236\213\346\263\250\350\247\243_\345\207\275\346\225\260\345\222\214\346\226\271\346\263\225.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/12_\347\261\273\345\236\213\346\263\250\350\247\243_Union\350\201\224\345\220\210\347\261\273\345\236\213.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/13_\345\244\232\346\200\201.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/\346\225\260\346\215\256\345\210\206\346\236\220\346\241\210\344\276\213/data_define.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/\346\225\260\346\215\256\345\210\206\346\236\220\346\241\210\344\276\213/file_define.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/\346\225\260\346\215\256\345\210\206\346\236\220\346\241\210\344\276\213/main.py" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/\346\225\260\346\215\256\345\210\206\346\236\220\346\241\210\344\276\213/\346\257\217\346\227\245\351\224\200\345\224\256\351\242\235\346\237\261\347\212\266\345\233\276.html" create mode 100644 "11_\351\235\242\345\220\221\345\257\271\350\261\241/\351\273\221\351\251\254\351\223\266\350\241\214ATM\346\241\210\344\276\213/main.py" create mode 100644 "12_sql/01_pymysql\345\205\245\351\227\250.py" create mode 100644 "12_sql/02_pymysql_\346\225\260\346\215\256\346\217\222\345\205\245.py" create mode 100644 12_sql/data_define.py create mode 100644 12_sql/file_define.py create mode 100644 12_sql/main.py create mode 100644 12_sql/main2.py create mode 100644 "13_pyspark/01_\345\237\272\347\241\200\345\207\206\345\244\207.py" create mode 100644 "13_pyspark/02_\346\225\260\346\215\256\350\276\223\345\205\245.py" create mode 100644 "13_pyspark/03_\346\225\260\346\215\256\350\256\241\347\256\227_map\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/04_\346\225\260\346\215\256\350\256\241\347\256\227_flatMap\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/05_\346\225\260\346\215\256\350\256\241\347\256\227_reduceByKey\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/06_\347\273\203\344\271\240\346\241\210\344\276\2131.py" create mode 100644 "13_pyspark/07_\346\225\260\346\215\256\350\256\241\347\256\227_filter\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/08_\346\225\260\346\215\256\350\256\241\347\256\227_distinct\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/09_\346\225\260\346\215\256\350\256\241\347\256\227_sortBy\346\226\271\346\263\225.py" create mode 100644 "13_pyspark/10_\347\273\203\344\271\240\346\241\210\344\276\2132.py" create mode 100644 "13_pyspark/11_\346\225\260\346\215\256\350\276\223\345\207\272_\350\276\223\345\207\272\344\270\272Python\345\257\271\350\261\241.py" create mode 100644 "13_pyspark/12_\346\225\260\346\215\256\350\276\223\345\207\272_\350\276\223\345\207\272\345\210\260\346\226\207\344\273\266.py" create mode 100644 "13_pyspark/13_\347\273\274\345\220\210\346\241\210\344\276\213.py" create mode 100644 "13_pyspark/14_\347\273\274\345\220\210\346\241\210\344\276\213_\351\233\206\347\276\244\350\277\220\350\241\214.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/01_\351\227\255\345\214\205.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/02_\350\243\205\351\245\260\345\231\250.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/03_\345\215\225\344\276\213\346\250\241\345\274\217/str_tools_py.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/03_\345\215\225\344\276\213\346\250\241\345\274\217/test.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/03_\345\215\225\344\276\213\346\250\241\345\274\217/test2.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/03_\345\215\225\344\276\213\346\250\241\345\274\217/\351\235\236\345\215\225\344\276\213\346\265\213\350\257\225.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/04_\345\267\245\345\216\202\346\250\241\345\274\217.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/05_\345\244\232\347\272\277\347\250\213\347\274\226\347\250\213.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/06_socket\347\274\226\347\250\213_\346\234\215\345\212\241\347\253\257\345\274\200\345\217\221.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/07_socket\347\274\226\347\250\213_\345\256\242\346\210\267\347\253\257\345\274\200\345\217\221.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/08_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217_\345\237\272\347\241\200\345\214\271\351\205\215.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/09_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217_\345\205\203\345\255\227\347\254\246\345\214\271\351\205\215.py" create mode 100644 "14_\351\253\230\347\272\247\346\212\200\345\267\247/10_\351\200\222\345\275\222.py" create mode 100644 data/input/Audio.wav create mode 100644 data/input/order.csv create mode 100644 data/input/wordcount.txt create mode 100644 my_package/__init__.py create mode 100644 my_package/my_module1.py create mode 100644 my_package/my_module2.py create mode 100644 my_utils/__init__.py create mode 100644 my_utils/file_util.py create mode 100644 my_utils/str_util.py create mode 100644 test_mysql.py create mode 100644 tmp/my.py create mode 100644 tmp/t2.py create mode 100644 tmp/test.py create mode 100644 tmp/test2.py diff --git a/chat_bot_opencat.py b/00-chartgpt/chat_bot_opencat.py similarity index 100% rename from chat_bot_opencat.py rename to 00-chartgpt/chat_bot_opencat.py diff --git "a/01_\344\275\240\345\245\275Python/01_\346\263\250\351\207\212.py" "b/01_\344\275\240\345\245\275Python/01_\346\263\250\351\207\212.py" new file mode 100644 index 0000000..031372b --- /dev/null +++ "b/01_\344\275\240\345\245\275Python/01_\346\263\250\351\207\212.py" @@ -0,0 +1,6 @@ +# 单行注释 + +""" +多行注释 +文档注释 +""" \ No newline at end of file diff --git "a/01_\344\275\240\345\245\275Python/02_\345\217\230\351\207\217.py" "b/01_\344\275\240\345\245\275Python/02_\345\217\230\351\207\217.py" new file mode 100644 index 0000000..31102ac --- /dev/null +++ "b/01_\344\275\240\345\245\275Python/02_\345\217\230\351\207\217.py" @@ -0,0 +1,8 @@ +""" +知识点:变量 +变量的定义格式: 变量名 = 变量值 +""" +# 定义一个变量:钱包, 用来存储余额数字 +money = 5 +# 查看一下,钱包还剩余多少钱 +print(money) diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/01_Python\344\270\255\347\232\204\345\255\227\351\235\242\351\207\217.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/01_Python\344\270\255\347\232\204\345\255\227\351\235\242\351\207\217.py" new file mode 100644 index 0000000..e7c930b --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/01_Python\344\270\255\347\232\204\345\255\227\351\235\242\351\207\217.py" @@ -0,0 +1,7 @@ +666 +13.14 +"黑马程序员" + +print(666) +print(13.14) +print("黑马程序员") \ No newline at end of file diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/02_Python\344\270\255\347\232\204\346\263\250\351\207\212.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/02_Python\344\270\255\347\232\204\346\263\250\351\207\212.py" new file mode 100644 index 0000000..d6fc797 --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/02_Python\344\270\255\347\232\204\346\263\250\351\207\212.py" @@ -0,0 +1,21 @@ +name = """ +多行注释 +""" +print(name) + +# 写一个整数字面量 +666 +# 写一个浮点数字面量 +13.14 +# 写一个字符串字面量 +"黑马程序员" + +# 通过print语句输出各类字面量 +print(666) +print(13.14) +print("黑马程序员") + +# 单行注释 +# +# +"""多行注释""" diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/03_Python\344\270\255\347\232\204\345\217\230\351\207\217.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/03_Python\344\270\255\347\232\204\345\217\230\351\207\217.py" new file mode 100644 index 0000000..ce8b258 --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/03_Python\344\270\255\347\232\204\345\217\230\351\207\217.py" @@ -0,0 +1,32 @@ +""" +演示Python中变量的相关操作 +""" + +# 定义一个变量,用来记录钱包余额 +money = 50 +# 通过print语句,输出变量记录的内容 +print("钱包还有:", money) + +# 买了一个冰淇淋,花费10元 +money = money - 20 +print("买了冰淇淋花费10元,还剩余:", money, "元") + +# 假设,每隔一小时,输出一下钱包的余额 +print("现在是下午1点,钱包余额剩余:", money) +print("现在是下午2点,钱包余额剩余:", money) +print("现在是下午3点,钱包余额剩余:", money) +print("现在是下午4点,钱包余额剩余:", money) + + +Name = "张三" +Age = 11 + + +name = "张三" +age = 11 + + + + + + diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/04_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/04_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213.py" new file mode 100644 index 0000000..c1c7e0f --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/04_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213.py" @@ -0,0 +1,19 @@ +# 方式1: 使用print直接输出类型信息 +print(type("黑马程序员")) +print(type(666)) +print(type(11.345)) + + +# 方式2: 使用变量存储type()语句的结果 +string_type = type("黑马程序员") +int_type = type(666) +float_type = type(11.345) +print(string_type) +print(int_type) +print(float_type) + + +# 方式3: 使用type()语句,查看变量中存储的数据类型信息 +name = "黑马程序员" +name_type = type(name) +print(name_type) diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213\350\275\254\346\215\242.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213\350\275\254\346\215\242.py" new file mode 100644 index 0000000..da729d1 --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\225\260\346\215\256\347\261\273\345\236\213\350\275\254\346\215\242.py" @@ -0,0 +1,25 @@ +# 将数字类型转换成字符串 +num_str = str(11) +print(type(num_str), num_str) + +float_str = str(11.345) +print(type(float_str), float_str) +# 将字符串转换成数字 +num = int("11") +print(type(num), num) + +num2 = float("11.345") +print(type(num2), num2) + +# 错误示例,想要将字符串转换成数字,必须要求字符串内的内容都是数字 +# num3 = int("黑马程序员") +# print(type(num3), num3) + +# 整数转浮点数 +float_num = float(11) +print(type(float_num), float_num) + +# 浮点数转整数 +int_num = int(11.345) +print(type(int_num), int_num) + diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\240\207\350\257\206\347\254\246.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\240\207\350\257\206\347\254\246.py" new file mode 100644 index 0000000..cea94cd --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/05_Python\344\270\255\347\232\204\346\240\207\350\257\206\347\254\246.py" @@ -0,0 +1,21 @@ +# 规则1:内容限定,限定只能使用:中文、英文、数字、下划线,注意:不能以数字开头 +# 错误的代码示范:1_name = "张三" +# 错误的代码示范:name_! = "张三" +name_ = "张三" +_name = "张三" +name_1 = "张三" + + +# 规则2:大小写敏感 +Itheima = "黑马程序员" +itheima = 666 +print(Itheima) +print(itheima) + + + +# 规则3:不可使用关键字 +# 错误的示例,使用了关键字:class = 1 +# 错误的示例,使用了关键字:def = 1 +Class = 1 + diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/06_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\213\274\346\216\245.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/06_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\213\274\346\216\245.py" new file mode 100644 index 0000000..d8cf612 --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/06_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\213\274\346\216\245.py" @@ -0,0 +1,12 @@ +# 字符串字面量之间的拼接 +print("学IT来黑马" + "月薪过万") +# 字符串字面量和字符串变量的拼接 +name = "黑马程序员" +address = "建材城东路9号院" +tel = 4006189090 + +# 不报错 +print("我是:" + name + ",我的地址是:" + address + ",我的电话是:" + str(tel)) + +# 报错 +print("我是:" + name + ",我的地址是:" + address + ",我的电话是:" + tel) diff --git "a/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/07_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\345\214\226.py" "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/07_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\345\214\226.py" new file mode 100644 index 0000000..15f07bc --- /dev/null +++ "b/02_Python\345\205\245\351\227\250\350\257\255\346\263\225/07_Python\347\232\204\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\345\214\226.py" @@ -0,0 +1,23 @@ +# 通过占位的形式,完成拼接 +name = "黑马程序员" +message = "学IT来:%s" % name +print(message) + +# 通过占位的形式,完成数字和字符串的拼接 +class_num = 57 +avg_salary = 16781 +message = "Python大数据学科,北京%s期,毕业平均工资:%s" % (class_num, avg_salary) +print(message) + +name = "传智播客" +setup_year = 2006 +stock_price = 19.99 +message = "%s,成立于:%d,我今天的股价是:%f" % (name, setup_year, stock_price) +print(message) + +num1 = 11 +num2 = 11.345 +print("数字11宽度限制5,结果是:%5d" % num1) +print("数字11宽度限制1,结果是:%1d" % num1) +print("数字11.345宽度限制7,小数精度2,结果是:%7.2f" % num2) +print("数字11.345不限制,小数精度2,结果是:%.2f" % num2) diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/01_\345\270\203\345\260\224\347\261\273\345\236\213\345\222\214\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/01_\345\270\203\345\260\224\347\261\273\345\236\213\345\222\214\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246.py" new file mode 100644 index 0000000..563317f --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/01_\345\270\203\345\260\224\347\261\273\345\236\213\345\222\214\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246.py" @@ -0,0 +1,34 @@ +""" +演示布尔类型的定义 +以及比较运算符的应用 +""" +# 定义变量存储布尔类型的数据 +bool_1 = True +bool_2 = False +print(f"bool_1变量的内容是:{bool_1}, 类型是:{type(bool_1)}") +print(f"bool_2变量的内容是:{bool_2}, 类型是:{type(bool_2)}") +# 比较运算符的使用 +# == , !=, >, <, >=, <= +# 演示进行内容的相等比较 +num1 = 10 +num2 = 10 +print(f"10 == 10的结果是:{num1 == num2}") + +num1 = 10 +num2 = 15 +print(f"10 != 15的结果是:{num1 != num2}") + +name1 = "itcast" +name2 = "itheima" +print(f"itcast == itheima 结果是:{name1 == name2}") + +# 演示大于小于,大于等于小于等于的比较运算 +num1 = 10 +num2 = 5 +print(f"10 > 5结果是:{num1 > num2}") +print(f"10 < 5的结果是:{num1 < num2}") + +num1 = 10 +num2 = 11 +print(f"10 >= 11的结果是:{num1 >= num2}") +print(f"10 <= 11的结果是:{num1 <= num2}") diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_2_\346\210\220\345\271\264\344\272\272\345\210\244\346\226\255\347\273\203\344\271\240\351\242\230.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_2_\346\210\220\345\271\264\344\272\272\345\210\244\346\226\255\347\273\203\344\271\240\351\242\230.py" new file mode 100644 index 0000000..bb04a34 --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_2_\346\210\220\345\271\264\344\272\272\345\210\244\346\226\255\347\273\203\344\271\240\351\242\230.py" @@ -0,0 +1,12 @@ +""" +演示练习题:成年人判断 +""" + +# 获取键盘输入 +age = int(input("请输入你的年龄:")) + +# 通过if判断是否是成年人 +if age >= 18: + print("您已成年,游玩需要买票,10元.") + +print("祝您游玩愉快") diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_if\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\237\272\347\241\200\346\240\274\345\274\217.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_if\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\237\272\347\241\200\346\240\274\345\274\217.py" new file mode 100644 index 0000000..6bf742f --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/02_if\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\237\272\347\241\200\346\240\274\345\274\217.py" @@ -0,0 +1,10 @@ +""" +演示Python判断语句:if语句的基本格式应用 +""" +age = 10 + +if age >= 18: + print("我已经成年了") + print("即将步入大学生活") + +print("时间过的真快呀") diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_2_\346\210\221\350\246\201\344\271\260\347\245\250\345\220\227\347\273\203\344\271\240\351\242\230.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_2_\346\210\221\350\246\201\344\271\260\347\245\250\345\220\227\347\273\203\344\271\240\351\242\230.py" new file mode 100644 index 0000000..4bd6228 --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_2_\346\210\221\350\246\201\344\271\260\347\245\250\345\220\227\347\273\203\344\271\240\351\242\230.py" @@ -0,0 +1,15 @@ +""" +演示if else练习题:我要买票吗 +""" + +# 定义键盘输入获取身高数据 +height = int(input("请输入你的身高(cm):")) + +# 通过if进行判断 +if height > 120: + print("您的身高超出120CM,需要买票,10元。") +else: + print("您的身高低于120CM,可以免费游玩。") + +print("祝您游玩愉快") + diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_if else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_if else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" new file mode 100644 index 0000000..12a72b3 --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/03_if else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" @@ -0,0 +1,13 @@ +""" +演示Python中 +if else的组合判断语句 +""" +age = int(input("请输入你的年龄:")) + +if age >= 18: + print("您已成年,需要买票10元。") +else: + print("您未成年,可以免费游玩。") + + + diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_2_\347\214\234\347\214\234\345\277\203\351\207\214\346\225\260\345\255\227\347\273\203\344\271\240\351\242\230.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_2_\347\214\234\347\214\234\345\277\203\351\207\214\346\225\260\345\255\227\347\273\203\344\271\240\351\242\230.py" new file mode 100644 index 0000000..e053fe4 --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_2_\347\214\234\347\214\234\345\277\203\351\207\214\346\225\260\345\255\227\347\273\203\344\271\240\351\242\230.py" @@ -0,0 +1,18 @@ +""" +演示if elif else练习题:猜猜心里数字 +""" + +# 定义一个变量数字 +num = 5 + +# 通过键盘输入获取猜想的数字,通过多次if 和 elif的组合进行猜想比较 +if int(input("请猜一个数字:")) == num: + print("恭喜第一次就猜对了呢") +elif int(input("猜错了,再猜一次:")) == num: + print("猜对了") +elif int(input("猜错了,再猜一次:")) == num: + print("恭喜,最后一次机会,你猜对了") +else: + print("Sorry 猜错了") + + diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_if_elif_else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_if_elif_else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" new file mode 100644 index 0000000..5215e1f --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/04_if_elif_else\350\257\255\345\217\245\347\232\204\344\275\277\347\224\250.py" @@ -0,0 +1,17 @@ +""" +演示if elif else 多条件判断语句的使用 +""" + +# 通过if判断,可以使用多条件判断的语法 +# 第一个条件就是if +if int(input("请输入你的身高(cm):")) < 120: + print("身高小于120cm,可以免费。") +elif int(input("请输入你的VIP等级(1-5):")) > 3: + print("vip级别大于3,可以免费。") +elif int(input("请告诉我今天几号:")) == 1: + print("今天是1号免费日,可以免费") +else: + print("不好意思,条件都不满足,需要买票10元。") + + + diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/05_\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\265\214\345\245\227.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/05_\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\265\214\345\245\227.py" new file mode 100644 index 0000000..8d9b62f --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/05_\345\210\244\346\226\255\350\257\255\345\217\245\347\232\204\345\265\214\345\245\227.py" @@ -0,0 +1,38 @@ +""" +演示判断语句的嵌套使用 +""" + +# if int(input("你的身高是多少:")) > 120: +# print("身高超出限制,不可以免费") +# print("但是,如果vip级别大于3,可以免费") +# +# if int(input("你的vip级别是多少:")) > 3: +# print("恭喜你,vip级别达标,可以免费") +# else: +# print("Sorry 你需要买票10元") +# else: +# print("欢迎小朋友,免费游玩。") + + +age = 11 +year = 1 +level = 1 +if age >= 18: + print("你是成年人") + if age < 30: + print("你的年龄达标了") + if year > 2: + print("恭喜你,年龄和入职时间都达标,可以领取礼物") + elif level > 3: + print("恭喜你,年龄和级别达标,可以领取礼物") + else: + print("不好意思,尽管年龄达标,但是入职时间和级别都不达标。") + + else: + print("不好意思,年龄太大了") + +else: + print("不好意思,小朋友不可以领取。") + + + diff --git "a/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/06_\345\210\244\346\226\255\350\257\255\345\217\245\345\256\236\346\210\230\346\241\210\344\276\213.py" "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/06_\345\210\244\346\226\255\350\257\255\345\217\245\345\256\236\346\210\230\346\241\210\344\276\213.py" new file mode 100644 index 0000000..55879b6 --- /dev/null +++ "b/03_Python\345\210\244\346\226\255\350\257\255\345\217\245/06_\345\210\244\346\226\255\350\257\255\345\217\245\345\256\236\346\210\230\346\241\210\344\276\213.py" @@ -0,0 +1,29 @@ +""" +演示判断语句的实战案例:终极猜数字 +""" +# 1. 构建一个随机的数字变量 +import random + +num = random.randint(1, 10) +guess_num = int(input("输入你要猜测的数字:")) +# 2. 通过if判断语句进行数字的猜测 +if guess_num == num: + print("恭喜,第一次就猜中了") +else: + if guess_num > num: + print("你猜测的数字大了") + else: + print("你猜测的数字小了") + guess_num = int(input("再次输入你要猜测的数字:")) + if guess_num == num: + print("恭喜,第二次猜中了") + else: + if guess_num > num: + print("你猜测的数字大了") + else: + print("你猜测的数字小了") + guess_num = int(input("第三次输入你要猜测的数字:")) + if guess_num == num: + print("第三次猜中了") + else: + print("三次机会用完了,没有猜中。") diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_2_while\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230_\346\261\2021-100\347\232\204\345\222\214.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_2_while\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230_\346\261\2021-100\347\232\204\345\222\214.py" new file mode 100644 index 0000000..6645468 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_2_while\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230_\346\261\2021-100\347\232\204\345\222\214.py" @@ -0,0 +1,10 @@ +""" +演示while循环基础练习题:求1-100的和 +""" +sum = 0 +i = 1 +while i <= 100: + sum += i + print(i) + i += 1 +print(f"1-100累加的和是:{sum}") diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" new file mode 100644 index 0000000..7462bbc --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/01_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" @@ -0,0 +1,7 @@ +""" +演示while循环的基础应用 +""" +i = 0 +while i < 100: + print("小美,我喜欢你") + i += 1 diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/02_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\346\241\210\344\276\213-\347\214\234\346\225\260\345\255\227.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/02_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\346\241\210\344\276\213-\347\214\234\346\225\260\345\255\227.py" new file mode 100644 index 0000000..35512cf --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/02_while\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\346\241\210\344\276\213-\347\214\234\346\225\260\345\255\227.py" @@ -0,0 +1,27 @@ +""" +演示while循环的基础案例 - 猜数字 +""" + +# 获取范围在1-100的随机数字 +import random +num = random.randint(1, 100) +# 定义一个变量,记录总共猜测了多少次 +count = 0 + +# 通过一个布尔类型的变量,做循环是否继续的标记 +flag = True +while flag: + guess_num = int(input("请输入你猜测的数字:")) + count += 1 + if guess_num == num: + print("猜中了") + # 设置为False就是终止循环的条件 + flag = False + else: + if guess_num > num: + print("你猜的大了") + else: + print("你猜的小了") + +print(f"你总共猜测了{count}次") + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/03_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\345\272\224\347\224\250.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/03_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\345\272\224\347\224\250.py" new file mode 100644 index 0000000..32c89bf --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/03_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\345\272\224\347\224\250.py" @@ -0,0 +1,22 @@ +""" +演示while循环的嵌套使用 +""" + +# 外层:表白100天的控制 +# 内层:每天的表白都送10只玫瑰花的控制 + +i = 1 +while i <= 100: + print(f"今天是第{i}天,准备表白.....") + + # 内层循环的控制变量 + j = 1 + while j <= 10: + print(f"送给小美第{j}只玫瑰花") + j += 1 + + print("小美,我喜欢你") + i += 1 + +print(f"坚持到第{i - 1}天,表白成功") + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/04_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\346\241\210\344\276\213-\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/04_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\346\241\210\344\276\213-\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" new file mode 100644 index 0000000..96fbf23 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/04_while\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\346\241\210\344\276\213-\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" @@ -0,0 +1,21 @@ +""" +演示使用while的嵌套循环 +打印输出九九乘法表 +""" + +# 定义外层循环的控制变量 +i = 1 +while i <= 9: + + # 定义内层循环的控制变量 + j = 1 + while j <= i: + # 内层循环的print语句,不要换行,通过\t制表符进行对齐 + print(f"{j} * {i} = {j * i}\t", end='') + j += 1 + + i += 1 + print() # print空内容,就是输出一个换行 + + + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_2_for\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230-\346\225\260\344\270\200\346\225\260\346\234\211\345\207\240\344\270\252a.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_2_for\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230-\346\225\260\344\270\200\346\225\260\346\234\211\345\207\240\344\270\252a.py" new file mode 100644 index 0000000..7bcd4f3 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_2_for\345\276\252\347\216\257\347\273\203\344\271\240\351\242\230-\346\225\260\344\270\200\346\225\260\346\234\211\345\207\240\344\270\252a.py" @@ -0,0 +1,23 @@ +""" +演示for循环的练习题:数一数有几个a +""" +# 统计如下字符串中,有多少个字母a +name = "itheima is a brand of itcast" + +# 定义一个变量,用来统计有多少个a +count = 0 + +# for 循环统计 +# for 临时变量 in 被统计的数据: +for x in name: + if x == "a": + count += 1 + +print(f"被统计的字符串中有{count}个a") + + + + + + + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_for\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_for\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" new file mode 100644 index 0000000..3effdd8 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/05_for\345\276\252\347\216\257\347\232\204\345\237\272\347\241\200\350\257\255\346\263\225.py" @@ -0,0 +1,13 @@ +""" +演示for循环的基础语法 +""" + +name = "itheima" + +for x in name: + # 将name的内容,挨个取出赋予x临时变量 + # 就可以在循环体内对x进行处理 + print(x) + + + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/06_range\350\257\255\345\217\245.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/06_range\350\257\255\345\217\245.py" new file mode 100644 index 0000000..b8e9ae6 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/06_range\350\257\255\345\217\245.py" @@ -0,0 +1,20 @@ +""" +演示Python中的range()语句的基本使用 +""" + +# range语法1 range(num) +# for x in range(10): +# print(x) + +# range 语法2 range(num1, num2) +# for x in range(5, 10): +# # 从5开始,到10结束(不包含10本身)的一个数字序列,数字之间间隔是1 +# print(x) + +# range 语法3 range(num1, num2, step) +# for x in range(5, 10, 2): +# # 从5开始,到10结束(不包含10本身)的一个数字序列,数字之间的间隔是2 +# print(x) + +for x in range(10): + print("送玫瑰花") diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/07_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/07_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" new file mode 100644 index 0000000..b9c91d5 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/07_\345\217\230\351\207\217\344\275\234\347\224\250\345\237\237.py" @@ -0,0 +1,9 @@ +""" +演示Python for循环临时变量的作用域 +""" +i = 0 +for i in range(5): + print(i) + +print(i) + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_2_for\345\276\252\347\216\257\346\211\223\345\215\260\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_2_for\345\276\252\347\216\257\346\211\223\345\215\260\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" new file mode 100644 index 0000000..d1ad539 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_2_for\345\276\252\347\216\257\346\211\223\345\215\260\344\271\235\344\271\235\344\271\230\346\263\225\350\241\250.py" @@ -0,0 +1,14 @@ +""" +演示for循环打印九九乘法表 +""" + +# 通过外层循环控制行数 +for i in range(1, 10): + # 通过内层循环控制每一行的数据 + for j in range(1, i + 1): + # 在内层循环中输出每一行的内容 + print(f"{j} * {i} = {j * i}\t", end='') + + # 外层循环可以通过print输出一个回车符 + print() + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_for\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\344\275\277\347\224\250.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_for\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\344\275\277\347\224\250.py" new file mode 100644 index 0000000..d8131f3 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/08_for\345\276\252\347\216\257\347\232\204\345\265\214\345\245\227\344\275\277\347\224\250.py" @@ -0,0 +1,20 @@ +""" +演示嵌套应用for循环 +""" + +# 坚持表白100天,每天都送10朵花 +# range +i = 0 +for i in range(1, 101): + print(f"今天是向小美表白的第{i}天,加油坚持。") + + # 写内层的循环了 + for j in range(1, 11): + print(f"给小美送的第{j}朵玫瑰花") + + print("小美我喜欢你") + +print(f"第{i}天,表白成功") + + + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\276\252\347\216\257\344\270\255\346\226\255.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\276\252\347\216\257\344\270\255\346\226\255.py" new file mode 100644 index 0000000..1be148e --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/09_\345\276\252\347\216\257\344\270\255\346\226\255.py" @@ -0,0 +1,51 @@ +""" +演示循环语句的中断控制:break和continue +""" +import random +num = random.randint(1, 10) + + + +# 演示循环中断语句 continue +# for i in range(1, 6): +# print("语句1") +# continue +# print("语句2") + +# 演示continue的嵌套应用 +# for i in range(1, 6): +# print("语句1") +# for j in range(1, 6): +# print("语句2") +# continue +# print("语句3") +# +# print("语句4") + +# 演示循环中断语句 break +# for i in range(1, 101): +# print("语句1") +# break +# print("语句2") +# +# print("语句3") + + +# 演示break的嵌套应用 +for i in range(1, 6): + print("语句1") + for j in range(1, 6): + print("语句2") + break + print("语句3") + + print("语句4") + + + + + +print(num) + + + diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/10_\345\276\252\347\216\257\347\273\274\345\220\210\346\241\210\344\276\213-\345\217\221\345\267\245\350\265\204.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/10_\345\276\252\347\216\257\347\273\274\345\220\210\346\241\210\344\276\213-\345\217\221\345\267\245\350\265\204.py" new file mode 100644 index 0000000..3859078 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/10_\345\276\252\347\216\257\347\273\274\345\220\210\346\241\210\344\276\213-\345\217\221\345\267\245\350\265\204.py" @@ -0,0 +1,17 @@ +age = int(input("请输入您的年龄:")) +if age >= 18: + if age < 30: + print("年龄满足继续判断") + if int(input("请输入您入职已有多少年:")) > 2: + print("年龄符合且入职超过2年,满足条件,可以领取") + exit() + else: + print("入职时间不满足继续判断") + if int(input("请输入您的职位级别:")) > 3: + print("年龄符合且级别超过3级,满足条件,可以领取") + else: + print("不好意思,您不满足领取条件") + else: + print("不好意思,年龄大于30岁,不满足领取条件。") +else: + print("不好意思,年龄小于18岁,不满足领取条件。") \ No newline at end of file diff --git "a/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/test.py" "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/test.py" new file mode 100644 index 0000000..7b02e54 --- /dev/null +++ "b/04_Python\345\276\252\347\216\257\350\257\255\345\217\245/test.py" @@ -0,0 +1,6 @@ + +# print("Hello", end='') +# print("world", end='') + +print("Hello\tWorld") +print("itheima\tbest") diff --git "a/05_\345\207\275\346\225\260/01_\345\207\275\346\225\260\345\277\253\351\200\237\344\275\223\351\252\214.py" "b/05_\345\207\275\346\225\260/01_\345\207\275\346\225\260\345\277\253\351\200\237\344\275\223\351\252\214.py" new file mode 100644 index 0000000..b0c05b5 --- /dev/null +++ "b/05_\345\207\275\346\225\260/01_\345\207\275\346\225\260\345\277\253\351\200\237\344\275\223\351\252\214.py" @@ -0,0 +1,9 @@ +""" +演示:快速体验函数的开发及应用 +""" +# 需求,统计字符串的长度,不使用内置函数len() + +print("欢迎来到黑马程序员!请出示您的健康码以及72小时核酸证明,并配合测量体温!") +print("体温测量中,您的体温是:37.3度,体温正常请进!") + + diff --git "a/05_\345\207\275\346\225\260/02_\345\207\275\346\225\260\345\256\232\344\271\211.py" "b/05_\345\207\275\346\225\260/02_\345\207\275\346\225\260\345\256\232\344\271\211.py" new file mode 100644 index 0000000..f54188b --- /dev/null +++ "b/05_\345\207\275\346\225\260/02_\345\207\275\346\225\260\345\256\232\344\271\211.py" @@ -0,0 +1,13 @@ +""" +演示函数的定义语法 +""" + +# 定义一个函数,输出相关信息 +def say_hi(): + print("Hi 我是黑马程序员,学Python来黑马") + +# 调用函数,让定义的函数开始工作 +say_hi() + + + diff --git "a/05_\345\207\275\346\225\260/03_\345\207\275\346\225\260\345\237\272\347\241\200\345\256\232\344\271\211\347\273\203\344\271\240\346\241\210\344\276\213.py" "b/05_\345\207\275\346\225\260/03_\345\207\275\346\225\260\345\237\272\347\241\200\345\256\232\344\271\211\347\273\203\344\271\240\346\241\210\344\276\213.py" new file mode 100644 index 0000000..944590f --- /dev/null +++ "b/05_\345\207\275\346\225\260/03_\345\207\275\346\225\260\345\237\272\347\241\200\345\256\232\344\271\211\347\273\203\344\271\240\346\241\210\344\276\213.py" @@ -0,0 +1,11 @@ +""" +演示函数基础定义练习案例:自动查核酸 +""" + +# 定义函数 +def check(): + # 编写函数体输出信息 + print("欢迎来到黑马程序员!\n请出示您的健康码以及72小时核酸证明!") + +# 调用函数 +check() diff --git "a/05_\345\207\275\346\225\260/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" "b/05_\345\207\275\346\225\260/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" new file mode 100644 index 0000000..95761ce --- /dev/null +++ "b/05_\345\207\275\346\225\260/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" @@ -0,0 +1,39 @@ +""" +演示对list列表的循环,使用while和for循环2种方式 +""" + + +def list_while_func(): + """ + 使用while循环遍历列表的演示函数 + :return: None + """ + my_list = ["传智教育", "黑马程序员", "Python"] + # 循环控制变量通过下标索引来控制,默认0 + # 每一次循环将下标索引变量+1 + # 循环条件:下标索引变量 < 列表的元素数量 + + # 定义一个变量用来标记列表的下标 + index = 0 # 初始值为0 + while index < len(my_list): + # 通过index变量取出对应下标的元素 + element = my_list[index] + print(f"列表的元素:{element}") + + # 至关重要 将循环变量(index)每一次循环都+1 + index += 1 + + +def list_for_func(): + """ + 使用for循环遍历列表的演示函数 + :return: None + """ + my_list = [1, 2, 3, 4, 5] + # for 临时变量 in 数据容器: + for element in my_list: + print(f"列表的元素有:{element}") + + +# list_while_func() +list_for_func() diff --git "a/05_\345\207\275\346\225\260/04_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260.py" "b/05_\345\207\275\346\225\260/04_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260.py" new file mode 100644 index 0000000..017f53e --- /dev/null +++ "b/05_\345\207\275\346\225\260/04_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260.py" @@ -0,0 +1,11 @@ +""" +演示函数使用参数 +""" + +# 定义2数相加的函数,通过参数接收被计算的2个数字 +def add(x, y, z): + result = x + y + z + print(f"{x} + {y} + {z}的计算结果是:{result}") + +# 调用函数,传入被计算的2个数字 +add(5, 6, 7) diff --git "a/05_\345\207\275\346\225\260/05_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260\347\273\203\344\271\240\346\241\210\344\276\213.py" "b/05_\345\207\275\346\225\260/05_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260\347\273\203\344\271\240\346\241\210\344\276\213.py" new file mode 100644 index 0000000..9190093 --- /dev/null +++ "b/05_\345\207\275\346\225\260/05_\345\207\275\346\225\260\347\232\204\345\217\202\346\225\260\347\273\203\344\271\240\346\241\210\344\276\213.py" @@ -0,0 +1,15 @@ +""" +演示函数的参数练习案例:升级自动查核酸 +""" + +# 定义函数,接收1个形式参数,数字类型,表示体温 +def check(num): + # 在函数体内进行判断体温 + print("欢迎来到黑马程序员!请出示您的健康码以及72小时核酸证明,并配合测量体温!") + if num <= 37.5: + print(f"体温测量中,您的体温是:{num}度,体温正常请进!") + else: + print(f"体温测量中,您的体温是:{num}度,需要隔离!") + +# 调用函数,传入实际参数 +check(37.6) diff --git "a/05_\345\207\275\346\225\260/06_\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236\345\200\274\345\256\232\344\271\211\350\257\255\346\263\225.py" "b/05_\345\207\275\346\225\260/06_\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236\345\200\274\345\256\232\344\271\211\350\257\255\346\263\225.py" new file mode 100644 index 0000000..859e805 --- /dev/null +++ "b/05_\345\207\275\346\225\260/06_\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236\345\200\274\345\256\232\344\271\211\350\257\255\346\263\225.py" @@ -0,0 +1,18 @@ +""" +演示:定义函数返回值的语法格式 +""" + + +# 定义一个函数,完成2数相加功能 +def add(a, b): + result = a + b + # 通过返回值,将相加的结果返回给调用者 + return result + # 返回结果后,还想输出一句话 + print("我完事了") + + +# 函数的返回值,可以通过变量去接收 +r = add(5, 6) +print(r) + diff --git "a/05_\345\207\275\346\225\260/07_None.py" "b/05_\345\207\275\346\225\260/07_None.py" new file mode 100644 index 0000000..05efff0 --- /dev/null +++ "b/05_\345\207\275\346\225\260/07_None.py" @@ -0,0 +1,35 @@ +""" +演示特殊字面量:None +""" + +# 无return语句的函数返回值 +def say_hi(): + print("你好呀") + +result = say_hi() +print(f"无返回值函数,返回的内容是:{result}") +print(f"无返回值函数,返回的内容类型是:{type(result)}") + +# 主动返回None的函数 +def say_hi2(): + print("你好呀") + return None + +result = say_hi2() +print(f"无返回值函数,返回的内容是:{result}") +print(f"无返回值函数,返回的内容类型是:{type(result)}") +# None用于if判断 +def check_age(age): + if age > 18: + return "SUCCESS" + else: + return None + +result = check_age(16) +if not result: + # 进入if表示result是None值 也就是False + print("未成年,不可以进入") + + +# None用于声明无初始内容的变量 +name = None diff --git "a/05_\345\207\275\346\225\260/08_\345\207\275\346\225\260\347\232\204\350\257\264\346\230\216\346\226\207\346\241\243.py" "b/05_\345\207\275\346\225\260/08_\345\207\275\346\225\260\347\232\204\350\257\264\346\230\216\346\226\207\346\241\243.py" new file mode 100644 index 0000000..8c9c08e --- /dev/null +++ "b/05_\345\207\275\346\225\260/08_\345\207\275\346\225\260\347\232\204\350\257\264\346\230\216\346\226\207\346\241\243.py" @@ -0,0 +1,18 @@ +""" +演示对函数进行文档说明 +""" + +# 定义函数,进行文档说明 +def add(x, y): + """ + add函数可以接收2个参数,进行2数相加的功能 + :param x: 形参x表示相加的其中一个数字 + :param y: 形参y表示相加的另一个数字 + :return: 返回值是2数相加的结果 + """ + result = x + y + print(f"2数相加的结果是:{result}") + return result + +add(5, 6) + diff --git "a/05_\345\207\275\346\225\260/09_\345\207\275\346\225\260\347\232\204\345\265\214\345\245\227\350\260\203\347\224\250.py" "b/05_\345\207\275\346\225\260/09_\345\207\275\346\225\260\347\232\204\345\265\214\345\245\227\350\260\203\347\224\250.py" new file mode 100644 index 0000000..5539aba --- /dev/null +++ "b/05_\345\207\275\346\225\260/09_\345\207\275\346\225\260\347\232\204\345\265\214\345\245\227\350\260\203\347\224\250.py" @@ -0,0 +1,17 @@ +""" +演示嵌套调用函数 +""" + +# 定义函数func_b +def func_b(): + print("---2---") +# 定义函数func_a,并在内部调用func_b +def func_a(): + print("---1---") + + # 嵌套调用func_b + func_b() + + print("---3---") +# 调用函数func_a +func_a() diff --git "a/05_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" "b/05_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" new file mode 100644 index 0000000..ac69cc1 --- /dev/null +++ "b/05_\345\207\275\346\225\260/10_\345\217\230\351\207\217\347\232\204\344\275\234\347\224\250\345\237\237.py" @@ -0,0 +1,55 @@ +""" +演示在函数使用的时候,定义的变量作用域 +""" + +# 演示局部变量 +# def test_a(): +# num = 100 +# print(num) +# +# +# test_a() +# 出了函数体,局部变量就无法使用了 +# print(num) + +# 演示全局变量 +# num = 200 +# +# def test_a(): +# print(f"test_a: {num}") +# +# def test_b(): +# print(f"test_b: {num}") +# +# test_a() +# test_b() +# print(num) + +# 在函数内修改全局变量 +# num = 200 +# +# def test_a(): +# print(f"test_a: {num}") +# +# def test_b(): +# num = 500 # 局部变量 +# print(f"test_b: {num}") +# +# test_a() +# test_b() +# print(num) + +# global关键字,在函数内声明变量为全局变量 +num = 200 + +def test_a(): + print(f"test_a: {num}") + +def test_b(): + global num # 设置内部定义的变量为全局变量 + num = 500 + print(f"test_b: {num}") + +test_a() +test_b() +print(num) diff --git "a/05_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" "b/05_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" new file mode 100644 index 0000000..12446ea --- /dev/null +++ "b/05_\345\207\275\346\225\260/11_\345\207\275\346\225\260\347\273\274\345\220\210\346\241\210\344\276\213.py" @@ -0,0 +1,62 @@ +""" +演示函数综合案例开发 +""" + +# 定义全局变量money name +money = 5000000 +name = None +# 要求客户输入姓名 +name = input("请输入您的姓名:") +# 定义查询函数 +def query(show_header): + if show_header: + print("-------------查询余额------------") + print(f"{name},您好,您的余额剩余:{money}元") + + +# 定义存款函数 +def saving(num): + global money # money在函数内部定义为全局变量 + money += num + print("-------------存款------------") + print(f"{name},您好,您存款{num}元成功。") + + # 调用query函数查询余额 + query(False) + +# 定义取款函数 +def get_money(num): + global money + money -= num + print("-------------取款------------") + print(f"{name},您好,您取款{num}元成功。") + + # 调用query函数查询余额 + query(False) +# 定义主菜单函数 +def main(): + print("-------------主菜单------------") + print(f"{name},您好,欢迎来到黑马银行ATM。请选择操作:") + print("查询余额\t[输入1]") + print("存款\t\t[输入2]") + print("取款\t\t[输入3]") # 通过\t制表符对齐输出 + print("退出\t\t[输入4]") + return input("请输入您的选择:") + +# 设置无限循环,确保程序不退出 +while True: + keyboard_input = main() + if keyboard_input == "1": + query(True) + continue # 通过continue继续下一次循环,一进来就是回到了主菜单 + elif keyboard_input == "2": + num = int(input("您想要存多少钱?请输入:")) + saving(num) + continue + elif keyboard_input == "3": + num = int(input("您想要取多少钱?请输入:")) + get_money(num) + continue + else: + print("程序退出啦") + break # 通过break退出循环 diff --git "a/05_\345\207\275\346\225\260/test.py" "b/05_\345\207\275\346\225\260/test.py" new file mode 100644 index 0000000..cd24844 --- /dev/null +++ "b/05_\345\207\275\346\225\260/test.py" @@ -0,0 +1,17 @@ + +print("----------------主菜单------------------") +print("周杰轮,您好,欢迎来到黑马银行ATM。请选择操作:") +print("查询余额\t[输入1]") +print("存款\t\t[输入2]") +print("取款\t\t[输入3]") +print("退出\t\t[输入4]") +input("请输入您的选择:") + +print() +print("----------------查询余额------------------") +print("周杰轮,您好,您的余额剩余:5000000元") +print("------------------------------") + +print("----------------取款------------------") +print("周杰轮,您好,您取款50000元成功") +print("周杰轮,您好,您的余额剩余:4950000元") diff --git "a/06_\345\207\275\346\225\260\350\277\233\351\230\266/01_\345\207\275\346\225\260\347\232\204\345\244\232\350\277\224\345\233\236\345\200\274.py" "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/01_\345\207\275\346\225\260\347\232\204\345\244\232\350\277\224\345\233\236\345\200\274.py" new file mode 100644 index 0000000..c4d0209 --- /dev/null +++ "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/01_\345\207\275\346\225\260\347\232\204\345\244\232\350\277\224\345\233\236\345\200\274.py" @@ -0,0 +1,14 @@ +""" +演示函数的多返回值示例 +""" + + +# 演示使用多个变量,接收多个返回值 +def test_return(): + return 1, "hello", True + + +x, y, z = test_return() +print(x) +print(y) +print(z) diff --git "a/06_\345\207\275\346\225\260\350\277\233\351\230\266/02_\345\207\275\346\225\260\345\217\202\346\225\260\347\232\204\345\244\232\347\247\215\344\275\277\347\224\250\345\275\242\345\274\217.py" "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/02_\345\207\275\346\225\260\345\217\202\346\225\260\347\232\204\345\244\232\347\247\215\344\275\277\347\224\250\345\275\242\345\274\217.py" new file mode 100644 index 0000000..29bff8b --- /dev/null +++ "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/02_\345\207\275\346\225\260\345\217\202\346\225\260\347\232\204\345\244\232\347\247\215\344\275\277\347\224\250\345\275\242\345\274\217.py" @@ -0,0 +1,31 @@ +""" +演示多种传参的形式 +""" +def user_info(name, age, gender): + print(f"姓名是:{name}, 年龄是:{age}, 性别是:{gender}") +# 位置参数 - 默认使用形式 +user_info('小明', 20, '男') + +# 关键字参数 +user_info(name='小王', age=11, gender='女') +user_info(age=10, gender='女', name='潇潇') # 可以不按照参数的定义顺序传参 +user_info('甜甜', gender='女', age=9) + +# 缺省参数(默认值) +def user_info(name, age, gender): + print(f"姓名是:{name}, 年龄是:{age}, 性别是:{gender}") + +user_info('小天', 13, '男') + + +# 不定长 - 位置不定长, *号 +# 不定长定义的形式参数会作为元组存在,接收不定长数量的参数传入 +def user_info(*args): + print(f"args参数的类型是:{type(args)},内容是:{args}") + +user_info(1, 2, 3, '小明', '男孩') + +# 不定长 - 关键字不定长, **号 +def user_info(**kwargs): + print(f"args参数的类型是:{type(kwargs)},内容是:{kwargs}") +user_info(name='小王', age=11, gender='男孩') diff --git "a/06_\345\207\275\346\225\260\350\277\233\351\230\266/03_\345\207\275\346\225\260\344\275\234\344\270\272\345\217\202\346\225\260\344\274\240\351\200\222.py" "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/03_\345\207\275\346\225\260\344\275\234\344\270\272\345\217\202\346\225\260\344\274\240\351\200\222.py" new file mode 100644 index 0000000..9904681 --- /dev/null +++ "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/03_\345\207\275\346\225\260\344\275\234\344\270\272\345\217\202\346\225\260\344\274\240\351\200\222.py" @@ -0,0 +1,15 @@ +""" +演示函数作为参数传递 +""" + +# 定义一个函数,接收另一个函数作为传入参数 +def test_func(compute): + result = compute(1, 2) # 确定compute是函数 + print(f"compute参数的类型是:{type(compute)}") + print(f"计算结果:{result}") + +# 定义一个函数,准备作为参数传入另一个函数 +def compute(x, y): + return x + y +# 调用,并传入函数 +test_func(compute) diff --git "a/06_\345\207\275\346\225\260\350\277\233\351\230\266/04_lambda\345\214\277\345\220\215\345\207\275\346\225\260.py" "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/04_lambda\345\214\277\345\220\215\345\207\275\346\225\260.py" new file mode 100644 index 0000000..45cb849 --- /dev/null +++ "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/04_lambda\345\214\277\345\220\215\345\207\275\346\225\260.py" @@ -0,0 +1,18 @@ +""" +演示lambda匿名函数 +""" + + +# 定义一个函数,接受其它函数输入 +def test_func(compute): + result = compute(1, 2) + print(f"结果是:{result}") + + +# 通过lambda匿名函数的形式,将匿名函数作为参数传入 +def add(x, y): + return x + y + + +test_func(add) +test_func(lambda x, y: x + y) diff --git "a/06_\345\207\275\346\225\260\350\277\233\351\230\266/test.py" "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/test.py" new file mode 100644 index 0000000..769aa8d --- /dev/null +++ "b/06_\345\207\275\346\225\260\350\277\233\351\230\266/test.py" @@ -0,0 +1,8 @@ + +def compute(add): + add(1, 2) + +def add(x, y): + print(x + y) + +compute(lambda x, y: print(x + y)) \ No newline at end of file diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/01_list\345\210\227\350\241\250.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/01_list\345\210\227\350\241\250.py" new file mode 100644 index 0000000..5aa8f3e --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/01_list\345\210\227\350\241\250.py" @@ -0,0 +1,36 @@ +""" +演示数据容器之:list列表 +语法:[元素,元素,....] +""" +# 定义一个列表 list +my_list = ["itheima", "itcast", "python"] +print(my_list) +print(type(my_list)) + +my_list = ["itheima", 666, True] +print(my_list) +print(type(my_list)) + +# 定义一个嵌套的列表 +my_list = [ [1, 2, 3], [4, 5, 6]] +print(my_list) +print(type(my_list)) + +# 通过下标索引取出对应位置的数据 +my_list = ["Tom", "Lily", "Rose"] +# 列表[下标索引], 从前向后从0开始,每次+1, 从后向前从-1开始,每次-1 +print(my_list[0]) +print(my_list[1]) +print(my_list[2]) +# 错误示范;通过下标索引取数据,一定不要超出范围 +# print(my_list[3]) + +# 通过下标索引取出数据(倒序取出) +print(my_list[-1]) +print(my_list[-2]) +print(my_list[-3]) + + +# 取出嵌套列表的元素 +my_list = [ [1, 2, 3], [4, 5, 6]] +print(my_list[1][1]) diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" new file mode 100644 index 0000000..c8595b1 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/02_list\345\210\227\350\241\250\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" @@ -0,0 +1,57 @@ +""" +演示数据容器之:list列表的常用操作 +""" +mylist = ["itcast", "itheima", "python"] +# 1.1 查找某元素在列表内的下标索引 +index = mylist.index("itheima") +print(f"itheima在列表中的下标索引值是:{index}") +# 1.2如果被查找的元素不存在,会报错 +# index = mylist.index("hello") +# print(f"hello在列表中的下标索引值是:{index}") + +# 2. 修改特定下标索引的值 +mylist[0] = "传智教育" +print(f"列表被修改元素值后,结果是:{mylist}") +# 3. 在指定下标位置插入新元素 +mylist.insert(1, "best") +print(f"列表插入元素后,结果是:{mylist}") +# 4. 在列表的尾部追加```单个```新元素 +mylist.append("黑马程序员") +print(f"列表在追加了元素后,结果是:{mylist}") +# 5. 在列表的尾部追加```一批```新元素 +mylist2 = [1, 2, 3] +mylist.extend(mylist2) +print(f"列表在追加了一个新的列表后,结果是:{mylist}") +# 6. 删除指定下标索引的元素(2种方式) +mylist = ["itcast", "itheima", "python"] + +# 6.1 方式1:del 列表[下标] +del mylist[2] +print(f"列表删除元素后结果是:{mylist}") +# 6.2 方式2:列表.pop(下标) +mylist = ["itcast", "itheima", "python"] +element = mylist.pop(2) +print(f"通过pop方法取出元素后列表内容:{mylist}, 取出的元素是:{element}") +# 7. 删除某元素在列表中的第一个匹配项 +mylist = ["itcast", "itheima", "itcast", "itheima", "python"] +mylist.remove("itheima") +print(f"通过remove方法移除元素后,列表的结果是:{mylist}") + +# 8. 清空列表 +mylist.clear() +print(f"列表被清空了,结果是:{mylist}") +# 9. 统计列表内某元素的数量 +mylist = ["itcast", "itheima", "itcast", "itheima", "python"] +count = mylist.count("itheima") +print(f"列表中itheima的数量是:{count}") + +# 10. 统计列表中全部的元素数量 +mylist = ["itcast", "itheima", "itcast", "itheima", "python"] +count = len(mylist) +print(f"列表的元素数量总共有:{count}个") + + + + + + diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/03_list\345\210\227\350\241\250\345\270\270\347\224\250\346\223\215\344\275\234\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/03_list\345\210\227\350\241\250\345\270\270\347\224\250\346\223\215\344\275\234\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..4b2b67a --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/03_list\345\210\227\350\241\250\345\270\270\347\224\250\346\223\215\344\275\234\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,24 @@ +""" +演示List常用操作的课后练习 +""" + +# 1. 定义这个列表,并用变量接收它, 内容是:[21, 25, 21, 23, 22, 20] +mylist = [21, 25, 21, 23, 22, 20] + +# 2. 追加一个数字31,到列表的尾部 +mylist.append(31) + +# 3. 追加一个新列表[29, 33, 30],到列表的尾部 +mylist.extend([29, 33, 30]) +# 4. 取出第一个元素(应是:21) +num1 = mylist[0] +print(f"从列表中取出来第一个元素,应该是21,实际上是:{num1}") + +# 5. 取出最后一个元素(应是:30) +num2 = mylist[-1] +print(f"从列表中取出来最后一个元素,应该是30,实际上是:{num2}") + +# 6. 查找元素31,在列表中的下标位置 +index = mylist.index(31) +print(f"元素31在列表的下标位置是:{index}") +print(f"最后列表的内容是:{mylist}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" new file mode 100644 index 0000000..bd58671 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/04_list\345\210\227\350\241\250\347\232\204\345\276\252\347\216\257.py" @@ -0,0 +1,23 @@ +""" +演示使用while和for循环遍历列表 +""" + + +def list_while_func(): + """ + 使用while循环遍历列表的演示函数 + :return: None + """ + mylist = ["传智教育", "黑马程序员", "Python"] + # 循环控制变量:通过下标索引来控制,默认0 + # 每一次循环将下标苏姚 + + + + +def list_for_func(): + """ + 使用for循环遍历列表的演示函数 + :return: + """ + diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/05_tuple\345\205\203\347\273\204.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/05_tuple\345\205\203\347\273\204.py" new file mode 100644 index 0000000..799da0c --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/05_tuple\345\205\203\347\273\204.py" @@ -0,0 +1,55 @@ +""" +演示tuple元组的定义和操作 +""" + +# 定义元组 +t1 = (1, "Hello", True) +t2 = () +t3 = tuple() +print(f"t1的类型是:{type(t1)}, 内容是:{t1}") +print(f"t2的类型是:{type(t2)}, 内容是:{t2}") +print(f"t3的类型是:{type(t3)}, 内容是:{t3}") + +# 定义单个元素的元素 +t4 = ("hello", ) +print(f"t4的类型是:{type(t4)}, t4的内容是:{t4}") +# 元组的嵌套 +t5 = ( (1, 2, 3), (4, 5, 6) ) +print(f"t5的类型是:{type(t5)}, 内容是:{t5}") + +# 下标索引去取出内容 +num = t5[1][2] +print(f"从嵌套元组中取出的数据是:{num}") + +# 元组的操作:index查找方法 +t6 = ("传智教育", "黑马程序员", "Python") +index = t6.index("黑马程序员") +print(f"在元组t6中查找黑马程序员,的下标是:{index}") +# 元组的操作:count统计方法 +t7 = ("传智教育", "黑马程序员", "黑马程序员", "黑马程序员", "Python") +num = t7.count("黑马程序员") +print(f"在元组t7中统计黑马程序员的数量有:{num}个") +# 元组的操作:len函数统计元组元素数量 +t8 = ("传智教育", "黑马程序员", "黑马程序员", "黑马程序员", "Python") +num = len(t8) +print(f"t8元组中的元素有:{num}个") +# 元组的遍历:while +index = 0 +while index < len(t8): + print(f"元组的元素有:{t8[index]}") + # 至关重要 + index += 1 + +# 元组的遍历:for +for element in t8: + print(f"2元组的元素有:{element}") + +# 修改元组内容 +# t8[0] = "itcast" + +# 定义一个元组 +t9 = (1, 2, ["itheima", "itcast"]) +print(f"t9的内容是:{t9}") +t9[2][0] = "黑马程序员" +t9[2][1] = "传智教育" +print(f"t9的内容是:{t9}") \ No newline at end of file diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" new file mode 100644 index 0000000..aa8e429 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/06_\345\255\227\347\254\246\344\270\262.py" @@ -0,0 +1,40 @@ +""" +演示以数据容器的角色,学习字符串的相关操作 +""" +my_str = "itheima and itcast" +# 通过下标索引取值 +value = my_str[2] +value2 = my_str[-16] +print(f"从字符串{my_str}取下标为2的元素,。值是:{value},取下标为-16的元素。值是:{value2}") + +# my_str[2] = "H" + +# index方法 +value = my_str.index("and") +print(f"在字符串{my_str}中查找and,其起始下标是:{value}") + +# replace方法 +new_my_str = my_str.replace("it", "程序") +print(f"将字符串{my_str},进行替换后得到:{new_my_str}") + +# split方法 +my_str = "hello python itheima itcast" +my_str_list = my_str.split(" ") +print(f"将字符串{my_str}进行split切分后得到:{my_str_list}, 类型是:{type(my_str_list)}") + +# strip方法 +my_str = " itheima and itcast " +new_my_str = my_str.strip() # 不传入参数,去除首尾空格 +print(f"字符串{my_str}被strip后,结果:{new_my_str}") + +my_str = "12itheima and itcast21" +new_my_str = my_str.strip("12") +print(f"字符串{my_str}被strip('12')后,结果:{new_my_str}") + +# 统计字符串中某字符串的出现次数, count +my_str = "itheima and itcast" +count = my_str.count("it") +print(f"字符串{my_str}中it出现的次数是:{count}") +# 统计字符串的长度, len() +num = len(my_str) +print(f"字符串{my_str}的长度是:{num}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/07_\345\255\227\347\254\246\344\270\262\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/07_\345\255\227\347\254\246\344\270\262\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..c7143fa --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/07_\345\255\227\347\254\246\344\270\262\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,14 @@ +""" +字符串课后练习演示 +"itheima itcast boxuegu" +""" +my_str = "itheima itcast boxuegu" +# 统计字符串内有多少个"it"字符 +num = my_str.count("it") +print(f"字符串{my_str}中有{num}个it字符") +# 将字符串内的空格,全部替换为字符:"|" +new_my_str = my_str.replace(" ", "|") +print(f"字符串{my_str}被替换空格后,结果是:{new_my_str}") +# 并按照"|"进行字符串分割,得到列表 +my_str_list = new_my_str.split("|") +print(f"字符串{new_my_str}按照|分割后结果是:{my_str_list}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" new file mode 100644 index 0000000..fb047f2 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/08_\345\272\217\345\210\227\345\222\214\345\210\207\347\211\207.py" @@ -0,0 +1,37 @@ +""" +演示对序列进行切片操作 +""" + +# 对list进行切片,从1开始,4结束,步长1 +my_list = [0, 1, 2, 3, 4, 5, 6] +result1 = my_list[1:4] # 步长默认是1,所以可以省略不写 +print(f"结果1:{result1}") + +# 对tuple进行切片,从头开始,到最后结束,步长1 +my_tuple = (0, 1, 2, 3, 4, 5, 6) +result2 = my_tuple[:] # 起始和结束不写表示从头到尾,步长为1可以省略 +print(f"结果2:{result2}") + +# 对str进行切片,从头开始,到最后结束,步长2 +my_str = "01234567" +result3 = my_str[::2] +print(f"结果3:{result3}") + + +# 对str进行切片,从头开始,到最后结束,步长-1 +my_str = "01234567" +result4 = my_str[::-1] # 等同于将序列反转了 +print(f"结果4:{result4}") + + +# 对列表进行切片,从3开始,到1结束,步长-1 +my_list = [0, 1, 2, 3, 4, 5, 6] +result5 = my_list[3:1:-1] +print(f"结果5:{result5}") + + +# 对元组进行切片,从头开始,到尾结束,步长-2 +my_tuple = (0, 1, 2, 3, 4, 5, 6) +result6 = my_tuple[::-2] +print(f"结果6:{result6}") + diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/09_\345\272\217\345\210\227\345\210\207\347\211\207\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/09_\345\272\217\345\210\227\345\210\207\347\211\207\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..0bc1559 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/09_\345\272\217\345\210\227\345\210\207\347\211\207\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,15 @@ +""" +演示序列的切片的课后练习 +"万过薪月,员序程马黑来,nohtyP学" +""" +my_str = "万过薪月,员序程马黑来,nohtyP学" +# 倒序字符串,切片取出 +result1 = my_str[::-1][9:14] +print(f"方式1结果:{result1}") +# 切片取出,然后倒序 +result2 = my_str[5:10][::-1] +print(f"方式2结果:{result2}") + +# split分隔"," replace替换"来"为空,倒序字符串 +result3 = my_str.split(",")[1].replace("来", "")[::-1] +print(f"方式3结果:{result3}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/10_\351\233\206\345\220\210.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/10_\351\233\206\345\220\210.py" new file mode 100644 index 0000000..0d46886 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/10_\351\233\206\345\220\210.py" @@ -0,0 +1,64 @@ +""" +演示数据容器集合的使用 +""" + +# 定义集合 +my_set = {"传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima", "传智教育", "黑马程序员", "itheima"} +my_set_empty = set() # 定义空集合 +print(f"my_set的内容是:{my_set}, 类型是:{type(my_set)}") +print(f"my_set_empty的内容是:{my_set_empty}, 类型是:{type(my_set_empty)}") + +# 添加新元素 +my_set.add("Python") +my_set.add("传智教育") # +print(f"my_set添加元素后结果是:{my_set}") +# 移除元素 +my_set.remove("黑马程序员") +print(f"my_set移除黑马程序员后,结果是:{my_set}") +# 随机取出一个元素 +my_set = {"传智教育", "黑马程序员", "itheima"} +element = my_set.pop() +print(f"集合被取出元素是:{element}, 取出元素后:{my_set}") + +# 清空集合, clear +my_set.clear() +print(f"集合被清空啦,结果是:{my_set}") + +# 取2个集合的差集 +set1 = {1, 2, 3} +set2 = {1, 5, 6} +set3 = set1.difference(set2) +print(f"取出差集后的结果是:{set3}") +print(f"取差集后,原有set1的内容:{set1}") +print(f"取差集后,原有set2的内容:{set2}") + + +# 消除2个集合的差集 +set1 = {1, 2, 3} +set2 = {1, 5, 6} +set1.difference_update(set2) +print(f"消除差集后,集合1结果:{set1}") +print(f"消除差集后,集合2结果:{set2}") + +# 2个集合合并为1个 +set1 = {1, 2, 3} +set2 = {1, 5, 6} +set3 = set1.union(set2) +print(f"2集合合并结果:{set3}") +print(f"合并后集合1:{set1}") +print(f"合并后集合2:{set2}") + +# 统计集合元素数量len() +set1 = {1, 2, 3, 4, 5, 1, 2, 3, 4, 5} +num = len(set1) +print(f"集合内的元素数量有:{num}个") + +# 集合的遍历 +# 集合不支持下标索引,不能用while循环 +# 可以用for循环 +set1 = {1, 2, 3, 4, 5} +for element in set1: + print(f"集合的元素有:{element}") + + + diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/11_\351\233\206\345\220\210\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/11_\351\233\206\345\220\210\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..7224efb --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/11_\351\233\206\345\220\210\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,19 @@ +""" +演示集合的课后练习题 +my_list = ['黑马程序员', '传智播客', '黑马程序员', '传智播客', + 'itheima', 'itcast', 'itheima', 'itcast', 'best'] +""" +my_list = ['黑马程序员', '传智播客', '黑马程序员', '传智播客', + 'itheima', 'itcast', 'itheima', 'itcast', 'best'] + +# 定义一个空集合 +my_set = set() + +# 通过for循环遍历列表 +for element in my_list: + # 在for循环中将列表的元素添加至集合 + my_set.add(element) + +# 最终得到元素去重后的集合对象,并打印输出 +print(f"列表的内容是:{my_list}") +print(f"通过for循环后,得到的集合对象是:{my_set}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/12_\345\255\227\345\205\270.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/12_\345\255\227\345\205\270.py" new file mode 100644 index 0000000..5ce537c --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/12_\345\255\227\345\205\270.py" @@ -0,0 +1,47 @@ +""" +演示数据容器字典的定义 +""" + +# 定义字典 +my_dict1 = {"王力鸿": 99, "周杰轮": 88, "林俊节": 77} +# 定义空字典 +my_dict2 = {} +my_dict3 = dict() +print(f"字典1的内容是:{my_dict1}, 类型:{type(my_dict1)}") +print(f"字典2的内容是:{my_dict2}, 类型:{type(my_dict2)}") +print(f"字典3的内容是:{my_dict3}, 类型:{type(my_dict3)}") + +# 定义重复Key的字典 +my_dict1 = {"王力鸿": 99, "王力鸿": 88, "林俊节": 77} +print(f"重复key的字典的内容是:{my_dict1}") + +# 从字典中基于Key获取Value +my_dict1 = {"王力鸿": 99, "周杰轮": 88, "林俊节": 77} +score = my_dict1["王力鸿"] +print(f"王力鸿的考试分数是:{score}") +score = my_dict1["周杰轮"] +print(f"周杰轮的考试分数是:{score}") +# 定义嵌套字典 +stu_score_dict = { + "王力鸿": { + "语文": 77, + "数学": 66, + "英语": 33 + }, "周杰轮": { + "语文": 88, + "数学": 86, + "英语": 55 + }, "林俊节": { + "语文": 99, + "数学": 96, + "英语": 66 + } +} +print(f"学生的考试信息是:{stu_score_dict}") + +# 从嵌套字典中获取数据 +# 看一下周杰轮的语文信息 +score = stu_score_dict["周杰轮"]["语文"] +print(f"周杰轮的语文分数是:{score}") +score = stu_score_dict["林俊节"]["英语"] +print(f"林俊节的英语分数是:{score}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/13_\345\255\227\345\205\270\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/13_\345\255\227\345\205\270\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" new file mode 100644 index 0000000..9a51ce9 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/13_\345\255\227\345\205\270\347\232\204\345\270\270\347\224\250\346\223\215\344\275\234.py" @@ -0,0 +1,37 @@ +""" +演示字典的常用操作 +""" +my_dict = {"周杰轮": 99, "林俊节": 88, "张学油": 77} +# 新增元素 +my_dict["张信哲"] = 66 +print(f"字典经过新增元素后,结果:{my_dict}") +# 更新元素 +my_dict["周杰轮"] = 33 +print(f"字典经过更新后,结果:{my_dict}") +# 删除元素 +score = my_dict.pop("周杰轮") +print(f"字典中被移除了一个元素,结果:{my_dict}, 周杰轮的考试分数是:{score}") + +# 清空元素, clear +my_dict.clear() +print(f"字典被清空了,内容是:{my_dict}") + +# 获取全部的key +my_dict = {"周杰轮": 99, "林俊节": 88, "张学油": 77} +keys = my_dict.keys() +print(f"字典的全部keys是:{keys}") +# 遍历字典 +# 方式1:通过获取到全部的key来完成遍历 +for key in keys: + print(f"字典的key是:{key}") + print(f"字典的value是:{my_dict[key]}") + +# 方式2:直接对字典进行for循环,每一次循环都是直接得到key +for key in my_dict: + print(f"2字典的key是:{key}") + print(f"2字典的value是:{my_dict[key]}") + +# 统计字典内的元素数量, len()函数 +num = len(my_dict) +print(f"字典中的元素数量有:{num}个") + diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/14_\345\255\227\345\205\270\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/14_\345\255\227\345\205\270\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..ad0ed03 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/14_\345\255\227\345\205\270\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,50 @@ +""" +演示字典的课后练习:升职加薪,对所有级别为1级的员工,级别上升1级,薪水增加1000元 +""" + +# 组织字典记录数据 +info_dict = { + "王力鸿": { + "部门": "科技部", + "工资": 3000, + "级别": 1 + }, + "周杰轮": { + "部门": "市场部", + "工资": 5000, + "级别": 2 + }, + "林俊节": { + "部门": "市场部", + "工资": 7000, + "级别": 3 + }, + "张学油": { + "部门": "科技部", + "工资": 4000, + "级别": 1 + }, + "刘德滑": { + "部门": "市场部", + "工资": 6000, + "级别": 2 + } +} + +print(f"员工在升值加薪之前的结果:{info_dict}") + +# for循环遍历字典 +for name in info_dict: + # if条件判断符合条件员工 + if info_dict[name]["级别"] == 1: + # 升职加薪操作 + # 获取到员工的信息字典 + employee_info_dict = info_dict[name] + # 修改员工的信息 + employee_info_dict["级别"] = 2 # 级别+1 + employee_info_dict["工资"] += 1000 # 工资+1000 + # 将员工的信息更新回info_dict + info_dict[name] = employee_info_dict + +# 输出结果 +print(f"对员工进行升级加薪后的结果是:{info_dict}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/15_\346\225\260\346\215\256\345\256\271\345\231\250\351\200\232\347\224\250\345\212\237\350\203\275.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/15_\346\225\260\346\215\256\345\256\271\345\231\250\351\200\232\347\224\250\345\212\237\350\203\275.py" new file mode 100644 index 0000000..e0b1ba8 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/15_\346\225\260\346\215\256\345\256\271\345\231\250\351\200\232\347\224\250\345\212\237\350\203\275.py" @@ -0,0 +1,70 @@ +""" +演示数据容器的通用功能 +""" +my_list = [1, 2, 3, 4, 5] +my_tuple = (1, 2, 3, 4, 5) +my_str = "abcdefg" +my_set = {1, 2, 3, 4, 5} +my_dict = {"key1": 1, "key2": 2, "key3": 3, "key4": 4, "key5": 5} + +# len元素个数 +print(f"列表 元素个数有:{len(my_list)}") +print(f"元组 元素个数有:{len(my_tuple)}") +print(f"字符串元素个数有:{len(my_str)}") +print(f"集合 元素个数有:{len(my_set)}") +print(f"字典 元素个数有:{len(my_dict)}") + +# max最大元素 +print(f"列表 最大的元素是:{max(my_list)}") +print(f"元组 最大的元素是:{max(my_tuple)}") +print(f"字符串最大的元素是:{max(my_str)}") +print(f"集合 最大的元素是:{max(my_set)}") +print(f"字典 最大的元素是:{max(my_dict)}") +# min最小元素 +print(f"列表 最小的元素是:{min(my_list)}") +print(f"元组 最小的元素是:{min(my_tuple)}") +print(f"字符串最小的元素是:{min(my_str)}") +print(f"集合 最小的元素是:{min(my_set)}") +print(f"字典 最小的元素是:{min(my_dict)}") +# 类型转换: 容器转列表 +print(f"列表转列表的结果是:{list(my_list)}") +print(f"元组转列表的结果是:{list(my_tuple)}") +print(f"字符串转列表结果是:{list(my_str)}") +print(f"集合转列表的结果是:{list(my_set)}") +print(f"字典转列表的结果是:{list(my_dict)}") +# 类型转换: 容器转元组 +print(f"列表转元组的结果是:{tuple(my_list)}") +print(f"元组转元组的结果是:{tuple(my_tuple)}") +print(f"字符串转元组结果是:{tuple(my_str)}") +print(f"集合转元组的结果是:{tuple(my_set)}") +print(f"字典转元组的结果是:{tuple(my_dict)}") +# 类型转换: 容器转字符串 +print(f"列表转字符串的结果是:{str(my_list)}") +print(f"元组转字符串的结果是:{str(my_tuple)}") +print(f"字符串转字符串结果是:{str(my_str)}") +print(f"集合转字符串的结果是:{str(my_set)}") +print(f"字典转字符串的结果是:{str(my_dict)}") +# 类型转换: 容器转集合 +print(f"列表转集合的结果是:{set(my_list)}") +print(f"元组转集合的结果是:{set(my_tuple)}") +print(f"字符串转集合结果是:{set(my_str)}") +print(f"集合转集合的结果是:{set(my_set)}") +print(f"字典转集合的结果是:{set(my_dict)}") +# 进行容器的排序 +my_list = [3, 1, 2, 5, 4] +my_tuple = (3, 1, 2, 5, 4) +my_str = "bdcefga" +my_set = {3, 1, 2, 5, 4} +my_dict = {"key3": 1, "key1": 2, "key2": 3, "key5": 4, "key4": 5} + +print(f"列表对象的排序结果:{sorted(my_list)}") +print(f"元组对象的排序结果:{sorted(my_tuple)}") +print(f"字符串对象的排序结果:{sorted(my_str)}") +print(f"集合对象的排序结果:{sorted(my_set)}") +print(f"字典对象的排序结果:{sorted(my_dict)}") + +print(f"列表对象的反向排序结果:{sorted(my_list, reverse=True)}") +print(f"元组对象的反向排序结果:{sorted(my_tuple, reverse=True)}") +print(f"字符串对象反向的排序结果:{sorted(my_str, reverse=True)}") +print(f"集合对象的反向排序结果:{sorted(my_set, reverse=True)}") +print(f"字典对象的反向排序结果:{sorted(my_dict, reverse=True)}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/16_\345\255\227\347\254\246\344\270\262\345\244\247\345\260\217\346\257\224\350\276\203.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/16_\345\255\227\347\254\246\344\270\262\345\244\247\345\260\217\346\257\224\350\276\203.py" new file mode 100644 index 0000000..fcd1c62 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/16_\345\255\227\347\254\246\344\270\262\345\244\247\345\260\217\346\257\224\350\276\203.py" @@ -0,0 +1,12 @@ +""" +演示字符串大小比较 +""" + +# abc 比较 abd +print(f"abd大于abc,结果:{'abd' > 'abc'}") +# a 比较 ab +print(f"ab大于a,结果:{'ab' > 'a'}") +# a 比较 A +print(f"a 大于 A,结果:{'a' > 'A'}") +# key1 比较 key2 +print(f"key2 > key1,结果:{'key2' > 'key1'}") diff --git "a/07_\346\225\260\346\215\256\345\256\271\345\231\250/test.py" "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/test.py" new file mode 100644 index 0000000..bfead51 --- /dev/null +++ "b/07_\346\225\260\346\215\256\345\256\271\345\231\250/test.py" @@ -0,0 +1,12 @@ + +my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +new_list = [] +i = 0 +while i < len(my_list): + if my_list[i] % 2 == 0: + new_list.append(my_list[i]) + i += 1 + +print(f"偶数形成的新列表:{new_list}") + + diff --git "a/08_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" new file mode 100644 index 0000000..9322f97 --- /dev/null +++ "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" @@ -0,0 +1,38 @@ +""" +演示对文件的读取 +""" + +# 打开文件 +import time + +f = open("D:/测试.txt", "r", encoding="UTF-8") +print(type(f)) +# 读取文件 - read() +# print(f"读取10个字节的结果:{f.read(10)}") +# print(f"read方法读取全部内容的结果是:{f.read()}") +print("-----------------------------------------------") +# 读取文件 - readLines() +# lines = f.readlines() # 读取文件的全部行,封装到列表中 +# print(f"lines对象的类型:{type(lines)}") +# print(f"lines对象的内容是:{lines}") + +# 读取文件 - readline() +# line1 = f.readline() +# line2 = f.readline() +# line3 = f.readline() +# print(f"第一行数据是:{line1}") +# print(f"第二行数据是:{line2}") +# print(f"第三行数据是:{line3}") + +# for循环读取文件行 +# for line in f: +# print(f"每一行数据是:{line}") +# # 文件的关闭 +# f.close() +# time.sleep(500000) +# with open 语法操作文件 +with open("D:/测试.txt", "r", encoding="UTF-8") as f: + for line in f: + print(f"每一行数据是:{line}") + +time.sleep(500000) \ No newline at end of file diff --git "a/08_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" new file mode 100644 index 0000000..ad7c499 --- /dev/null +++ "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -0,0 +1,22 @@ +""" +演示读取文件,课后练习题 +""" + +# 打开文件,以读取模式打开 +f = open("D:/word.txt", "r", encoding="UTF-8") +# 方式1:读取全部内容,通过字符串count方法统计itheima单词数量 +# content = f.read() +# count = content.count("itheima") +# print(f"itheima在文件中出现了:{count}次") +# 方式2:读取内容,一行一行读取 +count = 0 # 使用count变量来累计itheima出现的次数 +for line in f: + line = line.strip() # 去除开头和结尾的空格以及换行符 + words = line.split(" ") + for word in words: + if word == "itheima": + count += 1 # 如果单词是itheima,进行数量的累加加1 +# 判断单词出现次数并累计 +print(f"itheima出现的次数是:{count}") +# 关闭文件 +f.close() diff --git "a/08_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" new file mode 100644 index 0000000..508531e --- /dev/null +++ "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" @@ -0,0 +1,21 @@ +""" +演示文件的写入 +""" + +# 打开文件,不存在的文件, r, w, a +import time + +# f = open("D:/test.txt", "w", encoding="UTF-8") +# # write写入 +# f.write("Hello World!!!") # 内容写入到内存中 +# # flush刷新 +# # f.flush() # 将内存中积攒的内容,写入到硬盘的文件中 +# # close关闭 +# f.close() # close方法,内置了flush的功能的 +# 打开一个存在的文件 +f = open("D:/test.txt", "w", encoding="UTF-8") +# write写入、flush刷新 +f.write("黑马程序员") +# close关闭 +f.close() + diff --git "a/08_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" new file mode 100644 index 0000000..4d2e9e5 --- /dev/null +++ "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" @@ -0,0 +1,18 @@ +""" +演示文件的追加写入 +""" + +# 打开文件,不存在的文件 +# f = open("D:/test.txt", "a", encoding="UTF-8") +# # write写入 +# f.write("黑马程序员") +# # flush刷新 +# f.flush() +# # close关闭 +# f.close() +# 打开一个存在的文件 +f = open("D:/test.txt", "a", encoding="UTF-8") +# write写入、flush刷新 +f.write("\n月薪过万") +# close关闭 +f.close() diff --git "a/08_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" new file mode 100644 index 0000000..e58e9b8 --- /dev/null +++ "b/08_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" @@ -0,0 +1,22 @@ +""" +演示文件操作综合案例:文件备份 +""" + +# 打开文件得到文件对象,准备读取 +fr = open("D:/bill.txt", "r", encoding="UTF-8") +# 打开文件得到文件对象,准备写入 +fw = open("D:/bill.txt.bak", "w", encoding="UTF-8") +# for循环读取文件 +for line in fr: + line = line.strip() + # 判断内容,将满足的内容写出 + if line.split(",")[4] == "测试": + continue # continue进入下一次循环,这一次后面的内容就跳过了 + # 将内容写出去 + fw.write(line) + # 由于前面对内容进行了strip()的操作,所以要手动的写出换行符 + fw.write("\n") + +# close2个文件对象 +fr.close() +fw.close() # 写出文件调用close()会自动flush() diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/01_\346\274\224\347\244\272\345\274\202\345\270\270\347\232\204\345\207\272\347\216\260.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/01_\346\274\224\347\244\272\345\274\202\345\270\270\347\232\204\345\207\272\347\216\260.py" new file mode 100644 index 0000000..4f43b00 --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/01_\346\274\224\347\244\272\345\274\202\345\270\270\347\232\204\345\207\272\347\216\260.py" @@ -0,0 +1,6 @@ +""" +主动写一段错误代码,演示异常的出现 +""" + +# 通过open,读取一个不存在的文件 +f = open("D:/abc.txt", "r", encoding="UTF-8") diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/02_\345\274\202\345\270\270\347\232\204\346\215\225\350\216\267.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/02_\345\274\202\345\270\270\347\232\204\346\215\225\350\216\267.py" new file mode 100644 index 0000000..6df68e3 --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/02_\345\274\202\345\270\270\347\232\204\346\215\225\350\216\267.py" @@ -0,0 +1,37 @@ +""" +演示捕获异常 +""" + +# 基本捕获语法 +# try: +# f = open("D:/abc.txt", "r", encoding="UTF-8") +# except: +# print("出现异常了,因为文件不存在,我将open的模式,改为w模式去打开") +# f = open("D:/abc.txt", "w", encoding="UTF-8") + +# 捕获指定的异常 +# try: +# print(name) +# # 1 / 0 +# except NameError as e: +# print("出现了变量未定义的异常") +# print(e) +# 捕获多个异常 +# try: +# # 1 / 0 +# print(name) +# except (NameError, ZeroDivisionError) as e: +# print("出现了变量未定义 或者 除以0的异常错误") +# 未正确设置捕获异常类型,将无法捕获异常 + +# 捕获所有异常 +try: + f = open("D:/123.txt", "r", encoding="UTF-8") +except Exception as e: + print("出现异常了") + f = open("D:/123.txt", "w", encoding="UTF-8") +else: + print("好高兴,没有异常。") +finally: + print("我是finally,有没有异常我都要执行") + f.close() diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" new file mode 100644 index 0000000..1915b83 --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" @@ -0,0 +1,24 @@ +""" +演示异常的传递性 +""" + +# 定义一个出现异常的方法 +def func1(): + print("func1 开始执行") + num = 1 / 0 # 肯定有异常,除以0的异常 + print("func1 结束执行") +# 定义一个无异常的方法,调用上面的方法 + +def func2(): + print("func2 开始执行") + func1() + print("func2 结束执行") +# 定义一个方法,调用上面的方法 + +def main(): + try: + func2() + except Exception as e: + print(f"出现异常了,异常的信息是:{e}") + +main() diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/04_\346\250\241\345\235\227\347\232\204\345\257\274\345\205\245.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/04_\346\250\241\345\235\227\347\232\204\345\257\274\345\205\245.py" new file mode 100644 index 0000000..9f2a4db --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/04_\346\250\241\345\235\227\347\232\204\345\257\274\345\205\245.py" @@ -0,0 +1,46 @@ +""" +演示Python的模块导入 +""" + +from time import sleep + + + + + + + + + + + + + +# 使用import导入time模块使用sleep功能(函数) +# import time # 导入Python内置的time模块(time.py这个代码文件) +# print("你好") +# time.sleep(5) # 通过. 就可以使用模块内部的全部功能(类、函数、变量) +# print("我好") + +# 使用from导入time的sleep功能(函数) +# from time import sleep +# print("你好") +# sleep(5) +# print("我好") + +# 使用 * 导入time模块的全部功能 +# from time import * # *表示全部的意思 +# print("你好") +# sleep(5) +# print("我好") + +# 使用as给特定功能加上别名 +# import time as t +# print("你好") +# t.sleep(5) +# print("我好") + +from time import sleep as sl +print("你好") +sl(5) +print("我好") diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/05_\350\207\252\345\256\232\344\271\211\346\250\241\345\235\227.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/05_\350\207\252\345\256\232\344\271\211\346\250\241\345\235\227.py" new file mode 100644 index 0000000..aceca00 --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/05_\350\207\252\345\256\232\344\271\211\346\250\241\345\235\227.py" @@ -0,0 +1,21 @@ +""" +演示自定义模块 +""" + +# 导入自定义模块使用 +# import my_module1 +# from my_module1 import test +# test(1, 2) + +# 导入不同模块的同名功能 +# from my_module1 import test +# from my_module2 import test +# test(1, 2) +# __main__变量 +# from my_module1 import test + +# __all__变量 +from my_module1 import * +test_a(1, 2) +# test_b(2, 1) + diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" new file mode 100644 index 0000000..e82360a --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" @@ -0,0 +1,26 @@ +""" +演示Python的包 +""" + +# 创建一个包 +# 导入自定义的包中的模块,并使用 +# import my_package.my_module1 +# import my_package.my_module2 +# +# my_package.my_module1.info_print1() +# my_package.my_module2.info_print2() + +# from my_package import my_module1 +# from my_package import my_module2 +# my_module1.info_print1() +# my_module2.info_print2() + +# from my_package.my_module1 import info_print1 +# from my_package.my_module2 import info_print2 +# info_print1() +# info_print2() + +# 通过__all__变量,控制import * +from my_package import * +my_module1.info_print1() +my_module2.info_print2() diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" new file mode 100644 index 0000000..0e83d0c --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" @@ -0,0 +1,14 @@ +""" +演示异常、模块、包的综合案例练习 +""" +# 创建my_utils 包, 在包内创建:str_util.py 和 file_util.py 2个模块,并提供相应的函数 + +import my_utils.str_util +from my_utils import file_util + +print(my_utils.str_util.str_reverse("黑马程序员")) +print(my_utils.str_util.substr("itheima", 0, 4)) + + +file_util.append_to_file("D:/test_append.txt", "itheima") +file_util.print_file_info("D:/test_append.txt") diff --git "a/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" new file mode 100644 index 0000000..20f0054 --- /dev/null +++ "b/09_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" @@ -0,0 +1,18 @@ +""" +演示常用的模块功能 +""" +import time +# time模块 +ts = time.time() # 当前时间戳 +print(f"当前时间戳是:{ts}") + +# 获取当前时间以指定的格式显示,2000-01-01 10:00:00 +print(time.strftime("%Y-%m-%d %H:%M:%S")) + +# 将指定的时间戳转换为格式化的日期字符串 +print(time.strftime("%Y-%m-%d %H:%M:%S")) +# random模块 + +# os模块 + +# sys模块 diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/01_json\346\225\260\346\215\256\346\240\274\345\274\217.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/01_json\346\225\260\346\215\256\346\240\274\345\274\217.py" new file mode 100644 index 0000000..6485e84 --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/01_json\346\225\260\346\215\256\346\240\274\345\274\217.py" @@ -0,0 +1,24 @@ +""" +演示JSON数据和Python字典的相互转换 +""" +import json +# 准备列表,列表内每一个元素都是字典,将其转换为JSON +data = [{"name": "张大山", "age": 11}, {"name": "王大锤", "age": 13}, {"name": "赵小虎", "age": 16}] +json_str = json.dumps(data, ensure_ascii=False) +print(type(json_str)) +print(json_str) +# 准备字典,将字典转换为JSON +d = {"name":"周杰轮", "addr":"台北"} +json_str = json.dumps(d, ensure_ascii=False) +print(type(json_str)) +print(json_str) +# 将JSON字符串转换为Python数据类型[{k: v, k: v}, {k: v, k: v}] +s = '[{"name": "张大山", "age": 11}, {"name": "王大锤", "age": 13}, {"name": "赵小虎", "age": 16}]' +l = json.loads(s) +print(type(l)) +print(l) +# 将JSON字符串转换为Python数据类型{k: v, k: v} +s = '{"name": "周杰轮", "addr": "台北"}' +d = json.loads(s) +print(type(d)) +print(d) diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/02_pyecharts\345\237\272\347\241\200\345\205\245\351\227\250.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/02_pyecharts\345\237\272\347\241\200\345\205\245\351\227\250.py" new file mode 100644 index 0000000..37f100c --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/02_pyecharts\345\237\272\347\241\200\345\205\245\351\227\250.py" @@ -0,0 +1,23 @@ +""" +演示pyecharts的基础入门 +""" +# 导包 +from pyecharts.charts import Line +from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts +# 创建一个折线图对象 +line = Line() +# 给折线图对象添加x轴的数据 +line.add_xaxis(["中国", "美国", "英国"]) +# 给折线图对象添加y轴的数据 +line.add_yaxis("GDP", [30, 20, 10]) + +# 设置全局配置项set_global_opts来设置, +line.set_global_opts( + title_opts=TitleOpts(title="GDP展示", pos_left="center", pos_bottom="1%"), + legend_opts=LegendOpts(is_show=True), + toolbox_opts=ToolboxOpts(is_show=True), + visualmap_opts=VisualMapOpts(is_show=True), +) + +# 通过render方法,将代码生成为图像 +line.render() diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/03_\346\212\230\347\272\277\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/03_\346\212\230\347\272\277\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..9f892a6 --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/03_\346\212\230\347\272\277\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,68 @@ +""" +演示可视化需求1:折线图开发 +""" +import json +from pyecharts.charts import Line +from pyecharts.options import TitleOpts, LabelOpts + +# 处理数据 +f_us = open("D:/美国.txt", "r", encoding="UTF-8") +us_data = f_us.read() # 美国的全部内容 + +f_jp = open("D:/日本.txt", "r", encoding="UTF-8") +jp_data = f_jp.read() # 日本的全部内容 + +f_in = open("D:/印度.txt", "r", encoding="UTF-8") +in_data = f_in.read() # 印度的全部内容 + +# 去掉不合JSON规范的开头 +us_data = us_data.replace("jsonp_1629344292311_69436(", "") +jp_data = jp_data.replace("jsonp_1629350871167_29498(", "") +in_data = in_data.replace("jsonp_1629350745930_63180(", "") + +# 去掉不合JSON规范的结尾 +us_data = us_data[:-2] +jp_data = jp_data[:-2] +in_data = in_data[:-2] + +# JSON转Python字典 +us_dict = json.loads(us_data) +jp_dict = json.loads(jp_data) +in_dict = json.loads(in_data) + +# 获取trend key +us_trend_data = us_dict['data'][0]['trend'] +jp_trend_data = jp_dict['data'][0]['trend'] +in_trend_data = in_dict['data'][0]['trend'] + +# 获取日期数据,用于x轴,取2020年(到314下标结束) +us_x_data = us_trend_data['updateDate'][:314] +jp_x_data = jp_trend_data['updateDate'][:314] +in_x_data = in_trend_data['updateDate'][:314] + +# 获取确认数据,用于y轴,取2020年(到314下标结束) +us_y_data = us_trend_data['list'][0]['data'][:314] +jp_y_data = jp_trend_data['list'][0]['data'][:314] +in_y_data = in_trend_data['list'][0]['data'][:314] + +# 生成图表 +line = Line() # 构建折线图对象 +# 添加x轴数据 +line.add_xaxis(us_x_data) # x轴是公用的,所以使用一个国家的数据即可 +# 添加y轴数据 +line.add_yaxis("美国确诊人数", us_y_data, label_opts=LabelOpts(is_show=False)) # 添加美国的y轴数据 +line.add_yaxis("日本确诊人数", jp_y_data, label_opts=LabelOpts(is_show=False)) # 添加日本的y轴数据 +line.add_yaxis("印度确诊人数", in_y_data, label_opts=LabelOpts(is_show=False)) # 添加印度的y轴数据 + +# 设置全局选项 +line.set_global_opts( + # 标题设置 + title_opts=TitleOpts(title="2020年美日印三国确诊人数对比折线图", pos_left="center", pos_bottom="1%") +) + +# 调用render方法,生成图表 +line.render() +# 关闭文件对象 +f_us.close() +f_jp.close() +f_in.close() diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/04_\345\234\260\345\233\276\345\217\257\350\247\206\345\214\226\347\232\204\345\237\272\346\234\254\344\275\277\347\224\250.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/04_\345\234\260\345\233\276\345\217\257\350\247\206\345\214\226\347\232\204\345\237\272\346\234\254\344\275\277\347\224\250.py" new file mode 100644 index 0000000..1209843 --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/04_\345\234\260\345\233\276\345\217\257\350\247\206\345\214\226\347\232\204\345\237\272\346\234\254\344\275\277\347\224\250.py" @@ -0,0 +1,34 @@ +""" +演示地图可视化的基本使用 +""" +from pyecharts.charts import Map +from pyecharts.options import VisualMapOpts + +# 准备地图对象 +map = Map() +# 准备数据 +data = [ + ("北京", 99), + ("上海", 199), + ("湖南", 299), + ("台湾", 399), + ("广东", 499) +] +# 添加数据 +map.add("测试地图", data, "china") + +# 设置全局选项 +map.set_global_opts( + visualmap_opts=VisualMapOpts( + is_show=True, + is_piecewise=True, + pieces=[ + {"min": 1, "max": 9, "label": "1-9", "color": "#CCFFFF"}, + {"min": 10, "max": 99, "label": "10-99", "color": "#FF6666"}, + {"min": 100, "max": 500, "label": "100-500", "color": "#990033"} + ] + ) +) + +# 绘图 +map.render() diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/05_\345\205\250\345\233\275\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/05_\345\205\250\345\233\275\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..f78620c --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/05_\345\205\250\345\233\275\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,47 @@ +""" +演示全国疫情可视化地图开发 +""" +import json +from pyecharts.charts import Map +from pyecharts.options import * + +# 读取数据文件 +f = open("D:/疫情.txt", "r", encoding="UTF-8") +data = f.read() # 全部数据 +# 关闭文件 +f.close() +# 取到各省数据 +# 将字符串json转换为python的字典 +data_dict = json.loads(data) # 基础数据字典 +# 从字典中取出省份的数据 +province_data_list = data_dict["areaTree"][0]["children"] +# 组装每个省份和确诊人数为元组,并各个省的数据都封装入列表内 +data_list = [] # 绘图需要用的数据列表 +for province_data in province_data_list: + province_name = province_data["name"] # 省份名称 + province_confirm = province_data["total"]["confirm"] # 确诊人数 + data_list.append((province_name, province_confirm)) + + +# 创建地图对象 +map = Map() +# 添加数据 +map.add("各省份确诊人数", data_list, "china") +# 设置全局配置,定制分段的视觉映射 +map.set_global_opts( + title_opts=TitleOpts(title="全国疫情地图"), + visualmap_opts=VisualMapOpts( + is_show=True, # 是否显示 + is_piecewise=True, # 是否分段 + pieces=[ + {"min": 1, "max": 99, "lable": "1~99人", "color": "#CCFFFF"}, + {"min": 100, "max": 999, "lable": "100~9999人", "color": "#FFFF99"}, + {"min": 1000, "max": 4999, "lable": "1000~4999人", "color": "#FF9966"}, + {"min": 5000, "max": 9999, "lable": "5000~99999人", "color": "#FF6666"}, + {"min": 10000, "max": 99999, "lable": "10000~99999人", "color": "#CC3333"}, + {"min": 100000, "lable": "100000+", "color": "#990033"}, + ] + ) +) +# 绘图 +map.render("全国疫情地图.html") diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/06_\347\234\201\347\272\247\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/06_\347\234\201\347\272\247\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..4a2e4d3 --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/06_\347\234\201\347\272\247\347\226\253\346\203\205\345\217\257\350\247\206\345\214\226\345\234\260\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,50 @@ +""" +演示河南省疫情地图开发 +""" +import json +from pyecharts.charts import Map +from pyecharts.options import * + +# 读取文件 +f = open("D:/疫情.txt", "r", encoding="UTF-8") +data = f.read() +# 关闭文件 +f.close() +# 获取河南省数据 +# json数据转换为python字典 +data_dict = json.loads(data) +# 取到河南省数据 +cities_data = data_dict["areaTree"][0]["children"][3]["children"] + +# 准备数据为元组并放入list +data_list = [] +for city_data in cities_data: + city_name = city_data["name"] + "市" + city_confirm = city_data["total"]["confirm"] + data_list.append((city_name, city_confirm)) + +# 手动添加济源市的数据 +data_list.append(("济源市", 5)) + +# 构建地图 +map = Map() +map.add("河南省疫情分布", data_list, "河南") +# 设置全局选项 +map.set_global_opts( + title_opts=TitleOpts(title="河南省疫情地图"), + visualmap_opts=VisualMapOpts( + is_show=True, # 是否显示 + is_piecewise=True, # 是否分段 + pieces=[ + {"min": 1, "max": 99, "lable": "1~99人", "color": "#CCFFFF"}, + {"min": 100, "max": 999, "lable": "100~9999人", "color": "#FFFF99"}, + {"min": 1000, "max": 4999, "lable": "1000~4999人", "color": "#FF9966"}, + {"min": 5000, "max": 9999, "lable": "5000~99999人", "color": "#FF6666"}, + {"min": 10000, "max": 99999, "lable": "10000~99999人", "color": "#CC3333"}, + {"min": 100000, "lable": "100000+", "color": "#990033"}, + ] + ) +) + +# 绘图 +map.render("河南省疫情地图.html") diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/07_\345\237\272\347\241\200\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/07_\345\237\272\347\241\200\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..fba677a --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/07_\345\237\272\347\241\200\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,19 @@ +""" +演示基础柱状图的开发 +""" +from pyecharts.charts import Bar +from pyecharts.options import LabelOpts +# 使用Bar构建基础柱状图 +bar = Bar() +# 添加x轴的数据 +bar.add_xaxis(["中国", "美国", "英国"]) +# 添加y轴数据 +bar.add_yaxis("GDP", [30, 20, 10], label_opts=LabelOpts(position="right")) +# 反转x和y轴 +bar.reversal_axis() +# 绘图 +bar.render("基础柱状图.html") + +# 反转x轴和y轴 + +# 设置数值标签在右侧 \ No newline at end of file diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/08_\345\237\272\347\241\200\346\227\266\351\227\264\347\272\277\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/08_\345\237\272\347\241\200\346\227\266\351\227\264\347\272\277\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..6da82ad --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/08_\345\237\272\347\241\200\346\227\266\351\227\264\347\272\277\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,40 @@ +""" +演示带有时间线的柱状图开发 +""" +from pyecharts.charts import Bar, Timeline +from pyecharts.options import LabelOpts +from pyecharts.globals import ThemeType + +bar1 = Bar() +bar1.add_xaxis(["中国", "美国", "英国"]) +bar1.add_yaxis("GDP", [30, 30, 20], label_opts=LabelOpts(position="right")) +bar1.reversal_axis() + +bar2 = Bar() +bar2.add_xaxis(["中国", "美国", "英国"]) +bar2.add_yaxis("GDP", [50, 50, 50], label_opts=LabelOpts(position="right")) +bar2.reversal_axis() + +bar3 = Bar() +bar3.add_xaxis(["中国", "美国", "英国"]) +bar3.add_yaxis("GDP", [70, 60, 60], label_opts=LabelOpts(position="right")) +bar3.reversal_axis() + +# 构建时间线对象 +timeline = Timeline({"theme": ThemeType.LIGHT}) +# 在时间线内添加柱状图对象 +timeline.add(bar1, "点1") +timeline.add(bar2, "点2") +timeline.add(bar3, "点3") + +# 自动播放设置 +timeline.add_schema( + play_interval=1000, + is_timeline_show=True, + is_auto_play=True, + is_loop_play=True +) + +# 绘图是用时间线对象绘图,而不是bar对象了 +timeline.render("基础时间线柱状图.html") + diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/09_\346\213\223\345\261\225\347\237\245\350\257\206\347\202\271-\345\210\227\350\241\250\347\232\204sort\346\226\271\346\263\225.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/09_\346\213\223\345\261\225\347\237\245\350\257\206\347\202\271-\345\210\227\350\241\250\347\232\204sort\346\226\271\346\263\225.py" new file mode 100644 index 0000000..ec3662a --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/09_\346\213\223\345\261\225\347\237\245\350\257\206\347\202\271-\345\210\227\350\241\250\347\232\204sort\346\226\271\346\263\225.py" @@ -0,0 +1,17 @@ +""" +扩展列表的sort方法 +在学习了将函数作为参数传递后,我们可以学习列表的sort方法来对列表进行自定义排序 +""" + +# 准备列表 +my_list = [["a", 33], ["b", 55], ["c", 11]] + +# 排序,基于带名函数 +# def choose_sort_key(element): +# return element[1] +# +# my_list.sort(key=choose_sort_key, reverse=True) +# 排序,基于lambda匿名函数 +my_list.sort(key=lambda element: element[1], reverse=True) + +print(my_list) diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/10_GDP\345\212\250\346\200\201\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/10_GDP\345\212\250\346\200\201\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" new file mode 100644 index 0000000..f1458aa --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/10_GDP\345\212\250\346\200\201\346\237\261\347\212\266\345\233\276\345\274\200\345\217\221.py" @@ -0,0 +1,72 @@ +""" +演示第三个图表:GDP动态柱状图开发 +""" +from pyecharts.charts import Bar, Timeline +from pyecharts.options import * +from pyecharts.globals import ThemeType + +# 读取数据 +f = open("D:/1960-2019全球GDP数据.csv", "r", encoding="GB2312") +data_lines = f.readlines() +# 关闭文件 +f.close() +# 删除第一条数据 +data_lines.pop(0) +# 将数据转换为字典存储,格式为: +# { 年份: [ [国家, gdp], [国家,gdp], ...... ], 年份: [ [国家, gdp], [国家,gdp], ...... ], ...... } +# { 1960: [ [美国, 123], [中国,321], ...... ], 1961: [ [美国, 123], [中国,321], ...... ], ...... } +# 先定义一个字典对象 +data_dict = {} +for line in data_lines: + year = int(line.split(",")[0]) # 年份 + country = line.split(",")[1] # 国家 + gdp = float(line.split(",")[2]) # gdp数据 + # 如何判断字典里面有没有指定的key呢? + try: + data_dict[year].append([country, gdp]) + except KeyError: + data_dict[year] = [] + data_dict[year].append([country, gdp]) + +# print(data_dict[1960]) +# 创建时间线对象 +timeline = Timeline({"theme": ThemeType.LIGHT}) +# 排序年份 +sorted_year_list = sorted(data_dict.keys()) +for year in sorted_year_list: + data_dict[year].sort(key=lambda element: element[1], reverse=True) + # 取出本年份前8名的国家 + year_data = data_dict[year][0:8] + x_data = [] + y_data = [] + for country_gdp in year_data: + x_data.append(country_gdp[0]) # x轴添加国家 + y_data.append(country_gdp[1] / 100000000) # y轴添加gdp数据 + + # 构建柱状图 + bar = Bar() + x_data.reverse() + y_data.reverse() + bar.add_xaxis(x_data) + bar.add_yaxis("GDP(亿)", y_data, label_opts=LabelOpts(position="right")) + # 反转x轴和y轴 + bar.reversal_axis() + # 设置每一年的图表的标题 + bar.set_global_opts( + title_opts=TitleOpts(title=f"{year}年全球前8GDP数据") + ) + timeline.add(bar, str(year)) + + +# for循环每一年的数据,基于每一年的数据,创建每一年的bar对象 +# 在for中,将每一年的bar对象添加到时间线中 + +# 设置时间线自动播放 +timeline.add_schema( + play_interval=1000, + is_timeline_show=True, + is_auto_play=True, + is_loop_play=False +) +# 绘图 +timeline.render("1960-2019全球GDP前8国家.html") diff --git "a/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/1960-2019\345\205\250\347\220\203GDP\345\211\2158\345\233\275\345\256\266.html" "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/1960-2019\345\205\250\347\220\203GDP\345\211\2158\345\233\275\345\256\266.html" new file mode 100644 index 0000000..780f2c3 --- /dev/null +++ "b/10_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/1960-2019\345\205\250\347\220\203GDP\345\211\2158\345\233\275\345\256\266.html" @@ -0,0 +1,9546 @@ + + +
+ +