Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計
本篇介紹本彈性課程之開設由來, 以及一些供後續查閱之Python 之細節, 方便後面再回頭交叉索引之內容, 文獻等

“Talk is cheap. Show me the code.”
― Linus Torvalds

老子第41章
上德若谷
大白若辱
大方無隅
大器晚成
大音希聲
大象無形
道隱無名

拳打千遍, 身法自然

“There’s no shortage of remarkable ideas, what’s missing is the will to execute them.” – Seth Godin
「很棒的點子永遠不會匱乏,然而缺少的是執行點子的意志力。」—賽斯.高汀

Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計

本課程帶領同學以 Python turtle 實現 早期 Logo 海龜繪圖,藉由有趣的「海龜繪圖」學會基礎的 Python 程式設計

下圖: 本文作者以 Python 實現 板塊藝術

本篇作者模仿 “Coding Challenge #14: Fractal Trees - Recursive” 的用色呈現碎形樹

板塊藝術: codes 請參考 “遞歸 recursive, 碎形(分形 fractal), 藝術畫” 那部分,
(註: 參考自: 用 Logo語言繪製之板塊藝術, BFOIT
Introduction to Computer Programming
ref: http://guyhaas.com/bfoit/itp/Operators.html
link)

碎形樹: https://www.youtube.com/watch?v=0jjeOYMjmDU&t=8s, link
Pyhton codes 請參考本系列 “遞歸 recursive, 碎形(分形 fractal), 藝術畫” 那部分,
link
tree1_angle_headingLocal_20201011.py
背景色設為黑色
turtle.bgcolor('black')
T.pencolor('white')

本系列文章之連結

  • 從turtle海龜動畫學習Python-高中彈性課程1 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 2 安裝 Python, 線上執行 Python link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 3 烏龜繪圖 所需之Python基礎 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 4 烏龜開始畫圖 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 5 用函數封裝重複性指令-呼叫函數令烏龜畫正 n 邊形 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 6 畫多重旋轉圓,螺旋正方形 link

  • 從turtle海龜動畫 學習 Python - 7 遞歸 recursive - 高中彈性課程系列 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 8 碎形 (分形 fractal) link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 8.1 碎形 L-system link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 9 Python 物件導向介紹 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 9.1 Python 物件導向的練習 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10 藝術畫 自定義海龜形狀 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10.1 藝術畫 python繪製天然雪花結晶 https://blog.csdn.net/m0_47985483/article/details/122262036 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10.2 藝術畫 Python 製作生成式藝術 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 11.1 氣泡排序 - 用 turtle 呈現演算法之執行動作 link

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 11.2 maze 迷宮 - 用 turtle 呈現演算法之執行動作 link


文章目录

  • Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計
  • 本系列文章之連結
  • 緣起
  • 各項提示或補充之總表
    • Python內建的指令
    • 載入 模組 的語法有兩種
    • Python內建的隨機數指令
    • 查詢目前 Python 安裝了多少模組
    • 查詢目前 Python 有多少內建官方模組
    • 查詢某個模組有多少指令可以用
      • 如果要查內建模組 例如 math 或 turtle 模組
      • 如果要查外部模組 例如查詢 numpy 模組
    • turtle 有內建的畫圓的指令 circle()
    • 海龜打點 turtle.dot() 的效果
    • 海龜內建的形狀有六種
    • 自定義海龜形狀
      • 第一種方法 `turtle.get_poly()` 的方法
        • 以下測試第一個例子 正方形
        • 以下測試第二個例子 雪花形狀
      • 第二種方法 `turtle.Shape("compound")` 的方法
      • 第三種方法 `screen.register_shape("turtle.gif")` 的方法
      • 第四種方法 `screen.register_shape("triangle", ((5,-3), (0,5), (-5,-3)))` 的方法
    • 海龜蓋印 (依照當前的的形狀)
    • 調控動畫的速度
    • 打開 IDLE 編輯器 執行一連串的程式指令(草稿檔)
      • 正規的函數定義法 `def`, `return`
      • 匿名函數 lambda function
      • 高階函數: 函數可以輸入函數
      • 高階函數: 函數可以返回函數
      • 函數的輸入引數可以有預設值
      • 函數的輸入引數個數可以不確定
      • 5.5.1 注意函數的局部變數 local variable 與全域變數 global variable 之互動狀況
      • python 函数传参數是否会改变函数外部参数的值
      • 另外如果程式碼有輸入外部檔案內容的動作
    • 函數, 迴圈, 程式的終結退出 `return`, `break`, `quit()`, `exit()`, `sys.exit()`, `os.exit()` 等
    • 所謂模組 module 就是 副檔名.py 的檔案.
    • \_\_name\_\_ =="\_\_main\_\_" 的含意
    • recursive 遞迴函數
    • 5.5.1 注意函數的局部變數 local variable 與全域變數 global variable 之互動狀況
    • 補捉異常
    • 注意, 背景色, `bgcolor('black')` 的設定
    • 本課程用到物件導向的部分內容
    • 如何讓多隻海龜一起移動
    • 本課程用到多執行緒(多線程 threading 模組)的部分內容
      • 第一個最基本例子 產生一個 (副線程, 主線程之外的第二個) thread
      • 第二個最基本例子: 副線程的函數 wakeUp(), 可以輸入參數(引數 arguments):
    • Python list 的指令
      • 官網的手冊 3.1.3. List(串列)
      • 官網的手冊 5.1. 進一步了解 List(串列)
      • 5.1.1. 將 List 作為 Stack(堆疊)使用
      • 5.1.2. 將 List 作為 Queue(佇列)使用
      • 5.1.3. List Comprehensions(串列解析式)
    • stack 堆疊, 先進後出,在 Python 中, 可以用 list
    • queue 隊列, , 先進先出, 在 Python 中, 可以用 deque
    • Python 風格的寫法與功能
      • Python 等號的多重指定
      • 允許多個變量同時指定不同的值
      • 適當使用 串列解析式代替 for 迴圈
      • 使用 zip 來平行處理迭代器
  • References
    • 參考資料總表
    • 各次上課參考資料
  • 課程簡介
  • 課程大綱:
  • 上課紀錄
    • 第1次上課
    • 第2次上課
    • 第3次上課內容
    • 第4次上課內容
    • 第5次上課內容
    • 第6次上課內容

緣起

本課程是下學期 2020年 9 月預定在高雄市新莊高中開設之與數學有關之彈性課程-微課程之一, 以下是本課程講義之草稿.
6週為一輪,一次三節課,為每星期三第 5、6、7節(13:10-16:10),共18節課, 分量相當於1學分之大學課程
重複上兩輪, 讓選課同學可以選擇更適合之時間
第一輪日期:9/16、9/23、9/30、10/7、10/21、10/28
第二輪日期:11/4、11/11、11/18、12/2、12/9、12/16

以下是用 Python turtle module 畫碎形 dragon(龍形), 參考河西朝雄的 C codes 改寫

以下為自由軟體 GeoGebra 烏龜繪圖: 畫內嵌正4邊形m_18_ratio_0_18

以下為自由軟體 Scratch 繪製之 烏龜繪圖: 正多邊形按同一頂點不旋轉縮小

自由軟體 R 的烏龜繪圖

各項提示或補充之總表


以下我將內容分成初步及進階, 第一次讀, 可以跳過進階的部分, 以免見樹不見林
如果看到以下之註明:

  • 以下可以等進階時再細看
    , , , , , , ,
  • 以上可以等進階時再細看
    就表示此部分第一次讀, 可以跳過.

以後我們說明在IDLE中, 點選的的簡化符號就用, 例如 IDLE/Help/Turtle Demo
表示在 IDLE 中打開 Help, 再選 Turtle Demo


以下為之後會用到的 Python 內建的指令或相關功能之總提示之摘要列表, 同學可以用到時再來此處查看


Python內建的指令

Python內建的指令, 就是 IDLE 打開就可以用的指令

>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

內建_數學函數:
abs(), comlex(), max(), min(), pow(), round(), sorted(), sum(),
都是開箱即用.

內建指令當然相對較少且受限, 更進一步的指令, 則需載入相關 內建模組 modules, 內建模組無須安裝, 只要下 import 模組名 即可載入使用,

例如 math 數學模組, random 隨機模組, 海龜繪圖模組 turtle, 等等.

如果是外部模組, 例如 numpy, 則需先安裝, 再下import numpy 即可載入使用.

例如, 更進一步的數學函數則需載入內建的 math 模組
需下以下指令載入

>>> import math

內建的 math 模組的數學函數:
sin(), cos(), atan(),fmod(), ceil(), floor(), fabs(),factorial(), exp(), gcd(), pow(x,y),
log10(), sqrt(),fsum(), math.gamma(), math.pi, math.e, math.inf ( =float(‘inf’) ), math.nan ( =float(‘nan’))

https://docs.python.org/3/library/math.html

>>> import math
>>> dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs',
'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf',
'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod',
'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']

隨機數指令
需先載入內建的 random 模組

>>> import random

如果是海龜模組 turtle 為例, 也是內建模組, 不須要另外安裝,
只需要在程式碼一開始寫入
import turtle
或是
from turtle import *


載入 模組 的語法有兩種

以海龜模組 turtle 為例, 是內建模組, 不須要另外安裝,
只需要在程式碼一開始寫入
import turtle
或是
from turtle import *

如果是 import turtle 的載入方式, 必須在此模組的指令前加 turtle. ,
例如, 產生一隻新的海龜, 用
T = turtle.Turtle()
完整的步驟:

import turtle
T = turtle.Turtle()

如果是 from turtle import * 的載入方式, 此模組的指令不需前面加 turtle.
例如, 產生一隻新的海龜, 用
T = Turtle()
即可
完整的步驟:

from turtle import *
T = Turtle()

先補充一下, Python 如何產生隨機數

Python內建的隨機數指令

需先載入內建的 random 模組
>>> import random
產生隨機整數
>>> random.randint(1,10)
4
產生隨機 0~1 的小數
>>> random.random()
0.6428795725944434

>>> random.uniform(1,5)
1.3000399653858126

>>> data = range(1,11)
>>> random.choice(data)
9
>>> random.choice(data)
7
>>> random.choice(data)
4

random.shuffle 隨機洗牌(隨機排列)
(排列, np 的排列用 permutation與內建的sample()不同: >>> from numpy.random import permutation)
To shuffle an immutable sequence and return a new shuffled list,
use sample(x, k=len(x)) instead.

>>> data = [1,2,3,4,5,6,7]
>>> random.shuffle(data)
>>> data
[7, 1, 3, 4, 5, 6, 2]
>>> data_shuffle=random.shuffle(data)
>>> data_shuffle
>>> type(data_shuffle)
<class ‘NoneType’>

random.sample 隨機抽樣 (排列, np 的排列用 permutation與內建的sample()不同:
>>> from numpy.random import permutation)
Returns a new list containing elements from the population
while leaving the original population unchanged
To choose a sample from a range of integers, use a range() object as an argument.
This is especially fast and space efficient for sampling from a large population:
sample(range(10000000), k=60).
尺度大時, 建議用 range(n), 效能較高
>>> random.sample([1,2,3,4],2)
[4, 2]
>>> random.sample([1,2,3,4],4)
[2, 4, 1, 3]

random.randrange(a, b, step)

random.choices(seq, weights=None, *, cum_weights=None, k=1)


查詢目前 Python 安裝了多少模組

help('modules')

>>> help('modules')Please wait a moment while I gather a list of all available modules...Warning (from warnings module):File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\pkgutil.py", line 93__import__(info.name)
MatplotlibDeprecationWarning:
The matplotlib.compat module was deprecated in Matplotlib 3.3 and will be removed two minor releases later.Warning (from warnings module):File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\setuptools\distutils_patch.py", line 25warnings.warn(
UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
PIL                 asyncore            hyperparser         sched
__future__          atexit              idle                scipy
__main__            audioop             idle_test           scrolledlist
_abc                autocomplete        idlelib             seaborn
_aix_support        autocomplete_w      idna                search
_ast                autoexpand          imaplib             searchbase
_asyncio            base64              imghdr              searchengine
_bisect             bdb                 imp                 secrets
_blake2             binascii            importlib           select
_bootlocale         binhex              inspect             selectors
_bootsubprocess     bisect              io                  setuptools
_bz2                browser             iomenu              shelve
_codecs             builtins            ipaddress           shlex
_codecs_cn          bz2                 isympy              shutil
_codecs_hk          cProfile            itertools           sidebar
_codecs_iso2022     calendar            joblib              signal
_codecs_jp          calltip             json                site
_codecs_kr          calltip_w           keyword             six
_codecs_tw          certifi             kiwisolver          sklearn
_collections        cgi                 lib2to3             smtpd
_collections_abc    cgitb               linecache           smtplib
_compat_pickle      chardet             locale              sndhdr
_compression        chunk               logging             socket
_contextvars        cmath               lzma                socketserver
_csv                cmd                 macosx              sqlite3
_ctypes             code                mailbox             squeezer
_ctypes_test        codecontext         mailcap             sre_compile
_datetime           codecs              mainmenu            sre_constants
_decimal            codeop              marshal             sre_parse
_elementtree        collections         math                ssl
_functools          colorizer           matplotlib          stackviewer
_hashlib            colorsys            mimetypes           stat
_heapq              compileall          mmap                statistics
_imp                concurrent          modulefinder        statusbar
_io                 config              mpmath              string
_json               config_key          msilib              stringprep
_locale             configdialog        msvcrt              struct
_lsprof             configparser        multicall           subprocess
_lzma               contextlib          multiprocessing     sunau
_markupbase         contextvars         netrc               symbol
_md5                copy                nntplib             sympy
_msi                copyreg             nt                  symtable
_multibytecodec     crypt               ntpath              sys
_multiprocessing    csv                 nturl2path          sysconfig
_opcode             ctypes              numbers             tabnanny
_operator           curses              numpy               tarfile
_osx_support        cycler              opcode              telnetlib
_overlapped         dataclasses         operator            tempfile
_peg_parser         datetime            optparse            test
_pickle             dateutil            os                  textview
_py_abc             dbm                 outwin              textwrap
_pydecimal          debugger            pandas              this
_pyio               debugger_r          parenmatch          threading
_queue              debugobj            parser              threadpoolctl
_random             debugobj_r          pathbrowser         time
_sha1               decimal             pathlib             timeit
_sha256             delegator           pdb                 tkinter
_sha3               difflib             percolator          token
_sha512             dis                 pickle              tokenize
_signal             distutils           pickletools         tooltip
_sitebuiltins       doctest             pip                 trace
_socket             dynoption           pipes               traceback
_sqlite3            easy_install        pkg_resources       tracemalloc
_sre                editor              pkgutil             tree
_ssl                email               platform            tty
_stat               encodings           plistlib            turtle
_statistics         ensurepip           poplib              turtledemo
_string             enum                posixpath           types
_strptime           errno               pprint              typing
_struct             faulthandler        profile             undo
_symtable           filecmp             pstats              unicodedata
_testbuffer         fileinput           pty                 unittest
_testcapi           filelist            py_compile          urllib
_testconsole        fnmatch             pyclbr              urllib3
_testimportmultiple format              pydoc               uu
_testinternalcapi   formatter           pydoc_data          uuid
_testmultiphase     fractions           pyexpat             venv
_thread             ftplib              pylab               warnings
_threading_local    functools           pyparse             wave
_tkinter            gc                  pyparsing           weakref
_tracemalloc        genericpath         pyshell             webbrowser
_uuid               getopt              pytz                window
_warnings           getpass             query               winreg
_weakref            gettext             queue               winsound
_weakrefset         glob                quopri              wsgiref
_winapi             graphlib            random              xdrlib
_xxsubinterpreters  grep                re                  xml
_zoneinfo           gzip                redirector          xmlrpc
abc                 hashlib             replace             xxsubtype
aifc                heapq               reprlib             zipapp
antigravity         help                requests            zipfile
argparse            help_about          rlcompleter         zipimport
array               history             rpc                 zlib
ast                 hmac                run                 zoneinfo
asynchat            html                runpy               zoomheight
asyncio             http                runscript           zzdummyEnter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

查詢目前 Python 有多少內建官方模組

似乎沒有指令可以輸出內建官方模組的總表, 可以查詢, 連結到官網:

  1. Python 標準函式庫概覽
    https://docs.python.org/zh-tw/3/tutorial/stdlib.html link

  2. Python 標準函式庫概覽——第二部份
    https://docs.python.org/zh-tw/3/tutorial/stdlib2.html link

查詢某個模組有多少指令可以用

如果要查內建模組 例如 math 或 turtle 模組

例如 math 模組有多少指令可以用,
先載入 math,
import math

再下
help('math')

>>> help('math')
Help on built-in module math:NAMEmathDESCRIPTIONThis module provides access to the mathematical functionsdefined by the C standard.FUNCTIONSacos(x, /)Return the arc cosine (measured in radians) of x.The result is between 0 and pi.acosh(x, /)Return the inverse hyperbolic cosine of x.asin(x, /)Return the arc sine (measured in radians) of x.The result is between -pi/2 and pi/2.asinh(x, /)Return the inverse hyperbolic sine of x.atan(x, /)Return the arc tangent (measured in radians) of x.The result is between -pi/2 and pi/2.atan2(y, x, /)Return the arc tangent (measured in radians) of y/x.Unlike atan(y/x), the signs of both x and y are considered.atanh(x, /)Return the inverse hyperbolic tangent of x.ceil(x, /)Return the ceiling of x as an Integral.This is the smallest integer >= x.comb(n, k, /)Number of ways to choose k items from n items without repetition and without order.Evaluates to n! / (k! * (n - k)!) when k <= n and evaluatesto zero when k > n.Also called the binomial coefficient because it is equivalentto the coefficient of k-th term in polynomial expansion of theexpression (1 + x)**n.Raises TypeError if either of the arguments are not integers.Raises ValueError if either of the arguments are negative.copysign(x, y, /)Return a float with the magnitude (absolute value) of x but the sign of y.On platforms that support signed zeros, copysign(1.0, -0.0)returns -1.0.cos(x, /)Return the cosine of x (measured in radians).cosh(x, /)Return the hyperbolic cosine of x.degrees(x, /)Convert angle x from radians to degrees.dist(p, q, /)Return the Euclidean distance between two points p and q.The points should be specified as sequences (or iterables) ofcoordinates.  Both inputs must have the same dimension.Roughly equivalent to:sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))erf(x, /)Error function at x.erfc(x, /)Complementary error function at x.exp(x, /)Return e raised to the power of x.expm1(x, /)Return exp(x)-1.This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x.fabs(x, /)Return the absolute value of the float x.factorial(x, /)Find x!.Raise a ValueError if x is negative or non-integral.floor(x, /)Return the floor of x as an Integral.This is the largest integer <= x.fmod(x, y, /)Return fmod(x, y), according to platform C.x % y may differ.frexp(x, /)Return the mantissa and exponent of x, as pair (m, e).m is a float and e is an int, such that x = m * 2.**e.If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.fsum(seq, /)Return an accurate floating point sum of values in the iterable seq.Assumes IEEE-754 floating point arithmetic.gamma(x, /)Gamma function at x.gcd(*integers)Greatest Common Divisor.hypot(...)hypot(*coordinates) -> valueMultidimensional Euclidean distance from the origin to a point.Roughly equivalent to:sqrt(sum(x**2 for x in coordinates))For a two dimensional point (x, y), gives the hypotenuseusing the Pythagorean theorem:  sqrt(x*x + y*y).For example, the hypotenuse of a 3/4/5 right triangle is:>>> hypot(3.0, 4.0)5.0isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)Determine whether two floating point numbers are close in value.rel_tolmaximum difference for being considered "close", relative to themagnitude of the input valuesabs_tolmaximum difference for being considered "close", regardless of themagnitude of the input valuesReturn True if a is close in value to b, and False otherwise.For the values to be considered close, the difference between themmust be smaller than at least one of the tolerances.-inf, inf and NaN behave similarly to the IEEE 754 Standard.  Thatis, NaN is not close to anything, even itself.  inf and -inf areonly close to themselves.isfinite(x, /)Return True if x is neither an infinity nor a NaN, and False otherwise.isinf(x, /)Return True if x is a positive or negative infinity, and False otherwise.isnan(x, /)Return True if x is a NaN (not a number), and False otherwise.isqrt(n, /)Return the integer part of the square root of the input.lcm(*integers)Least Common Multiple.ldexp(x, i, /)Return x * (2**i).This is essentially the inverse of frexp().lgamma(x, /)Natural logarithm of absolute value of Gamma function at x.log(...)log(x, [base=math.e])Return the logarithm of x to the given base.If the base not specified, returns the natural logarithm (base e) of x.log10(x, /)Return the base 10 logarithm of x.log1p(x, /)Return the natural logarithm of 1+x (base e).The result is computed in a way which is accurate for x near zero.log2(x, /)Return the base 2 logarithm of x.modf(x, /)Return the fractional and integer parts of x.Both results carry the sign of x and are floats.nextafter(x, y, /)Return the next floating-point value after x towards y.perm(n, k=None, /)Number of ways to choose k items from n items without repetition and with order.Evaluates to n! / (n - k)! when k <= n and evaluatesto zero when k > n.If k is not specified or is None, then k defaults to nand the function returns n!.Raises TypeError if either of the arguments are not integers.Raises ValueError if either of the arguments are negative.pow(x, y, /)Return x**y (x to the power of y).prod(iterable, /, *, start=1)Calculate the product of all the elements in the input iterable.The default start value for the product is 1.When the iterable is empty, return the start value.  This function isintended specifically for use with numeric values and may rejectnon-numeric types.radians(x, /)Convert angle x from degrees to radians.remainder(x, y, /)Difference between x and the closest integer multiple of y.Return x - n*y where n*y is the closest integer multiple of y.In the case where x is exactly halfway between two multiples ofy, the nearest even value of n is used. The result is always exact.sin(x, /)Return the sine of x (measured in radians).sinh(x, /)Return the hyperbolic sine of x.sqrt(x, /)Return the square root of x.tan(x, /)Return the tangent of x (measured in radians).tanh(x, /)Return the hyperbolic tangent of x.trunc(x, /)Truncates the Real x to the nearest Integral toward 0.Uses the __trunc__ magic method.ulp(x, /)Return the value of the least significant bit of the float x.DATAe = 2.718281828459045inf = infnan = nanpi = 3.141592653589793tau = 6.283185307179586FILE(built-in)

如果要查外部模組 例如查詢 numpy 模組

有關 外部模組的說明可以參考: 用 Python+Numpy+scipy 執行 Matlab 的矩陣計算 1 Python科學計算第三方庫, 原生指令, 內建模組, 外部模組 link

例如查詢 numpy 模組有多少指令可以用,
必須先安裝
假設你是用微軟視窗, 在命令提示字元下
pip install numpy

再在 Python IDLE 載入 numpy,
>>>import numpy

再下
>>>help('numpy')

截至 python 3.10 版
出現 83585行的文字壓縮說明
量相當大

可以單獨查詢某個指令, 例如, 產生 numpy 陣列的指令
numpy.array

help(numpy.array)
Help on built-in function array in module numpy:array(...)array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0,like=None)Create an array.Parameters----------object : array_likeAn array, any object exposing the array interface, an object whose__array__ method returns an array, or any (nested) sequence.If object is a scalar, a 0-dimensional array containing object isreturned.dtype : data-type, optionalThe desired data-type for the array.  If not given, then the type willbe determined as the minimum type required to hold the objects in thesequence.copy : bool, optionalIf true (default), then the object is copied.  Otherwise, a copy willonly be made if __array__ returns a copy, if obj is a nested sequence,or if a copy is needed to satisfy any of the other requirements(`dtype`, `order`, etc.).order : {'K', 'A', 'C', 'F'}, optionalSpecify the memory layout of the array. If object is not an array, thenewly created array will be in C order (row major) unless 'F' isspecified, in which case it will be in Fortran order (column major).If object is an array the following holds.===== ========= ===================================================order  no copy                     copy=True===== ========= ==================================================='K'   unchanged F & C order preserved, otherwise most similar order'A'   unchanged F order if input is F and not C, otherwise C order'C'   C order   C order'F'   F order   F order===== ========= ===================================================When ``copy=False`` and a copy is made for other reasons, the result isthe same as if ``copy=True``, with some exceptions for 'A', see theNotes section. The default order is 'K'.subok : bool, optionalIf True, then sub-classes will be passed-through, otherwisethe returned array will be forced to be a base-class array (default).ndmin : int, optionalSpecifies the minimum number of dimensions that the resultingarray should have.  Ones will be pre-pended to the shape asneeded to meet this requirement.like : array_likeReference object to allow the creation of arrays which are notNumPy arrays. If an array-like passed in as ``like`` supportsthe ``__array_function__`` protocol, the result will be definedby it. In this case, it ensures the creation of an array objectcompatible with that passed in via this argument... versionadded:: 1.20.0Returns-------out : ndarrayAn array object satisfying the specified requirements.See Also--------empty_like : Return an empty array with shape and type of input.ones_like : Return an array of ones with shape and type of input.zeros_like : Return an array of zeros with shape and type of input.full_like : Return a new array with shape of input filled with value.empty : Return a new uninitialized array.ones : Return a new array setting values to one.zeros : Return a new array setting values to zero.full : Return a new array of given shape filled with value.Notes-----When order is 'A' and `object` is an array in neither 'C' nor 'F' order,and a copy is forced by a change in dtype, then the order of the result isnot necessarily 'C' as expected. This is likely a bug.Examples-------->>> np.array([1, 2, 3])array([1, 2, 3])Upcasting:>>> np.array([1, 2, 3.0])array([ 1.,  2.,  3.])More than one dimension:>>> np.array([[1, 2], [3, 4]])array([[1, 2],[3, 4]])Minimum dimensions 2:>>> np.array([1, 2, 3], ndmin=2)array([[1, 2, 3]])Type provided:>>> np.array([1, 2, 3], dtype=complex)array([ 1.+0.j,  2.+0.j,  3.+0.j])Data-type consisting of more than one element:>>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])>>> x['a']array([1, 3])Creating an array from sub-classes:>>> np.array(np.mat('1 2; 3 4'))array([[1, 2],[3, 4]])>>> np.array(np.mat('1 2; 3 4'), subok=True)matrix([[1, 2],[3, 4]])

turtle 有內建的畫圓的指令 circle()

circle() 畫圓, 參數是半徑 (沒有ellipse)
circle(radius, extent=None, steps=None), 也可以用此指令可以畫出正多邊形
dot() 在該地點畫一黑點


海龜打點 turtle.dot() 的效果

  1. 可以產生許多圓形彩色大小隨意的圓盤
  2. 可以呈現迷宮或是某些演算法, 走過之位置
    可以參考 https://blog.csdn.net/weixin_45901519/article/details/109456646 link

    這份迷宮程式碼稍微複雜, 把程式碼複製, 存為.py檔, 迷宮初始資料複製到 maze2.txt, 放在同一資料夾下, 就可以執行.

海龜內建的形狀有六種

shape_foo=["turtle","classic","arrow","circle","square","triangle"]
{海龜, 古典箭頭, 較大的箭頭, 圓, 正方形, 三角形}
預設是 classic, 是類似箭號之形狀


自定義海龜形狀

詳細作法枝例子可以參考本系列:

  • 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10 藝術畫 自定義海龜形狀 link

第一種方法 turtle.get_poly() 的方法

如果只有一個形狀, 可以用此方法較單純:
get_poly() 的方法

流程:
begin_poly()
做動作: 海龜畫出一個多邊形, 或畫一個任意形狀
end_poly()
再用 register_shape() 取名稱註冊成一個形狀
register_shape("myshape", get_poly())
再將海龜形狀令為此新定義之形狀 “myshape”
T.shape("myShape")

begin_poly()
,,,,# 海龜畫出一個多邊形
end_poly()
register_shape("myshape", get_poly())

以下測試第一個例子 正方形

先畫一個正方形, 再註冊為一個形狀, 再令海龜取用此形狀

# -*- coding: utf-8 -*-# set custom shape 20160617
#Turtle 24.1. Turtle graphics — Python v3.3# Tested by Prof. P-J Lai MATH NKNU 20210103
##24.1.3.7. Special Turtle methods
##begin_poly()
##end_poly()
##register_shape("myshape",get_poly())
##T.shape("myShape")
##較單純!# custom_Shape_get_poly().pyimport turtle
T=turtle.Turtle()T.home()
T.begin_poly()
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.end_poly()
myPoly=T.get_poly()
turtle.register_shape("myShape", myPoly)
T.shape("myShape")T.turtlesize(5)
T.color('red')
T.forward(100)

注意: 可以把
myPoly=T.get_poly()
turtle.register_shape("myShape", myPoly)
改成
turtle.register_shape("myShape",T.get_poly())

效果一樣!

# -*- coding: utf-8 -*-# set custom shape 20160617
#Turtle 24.1. Turtle graphics — Python v3.3# Tested by Prof. P-J Lai MATH NKNU 20210103
##24.1.3.7. Special Turtle methods
##begin_poly()
##end_poly()
##register_shape("myshape",get_poly())
##T.shape("myShape")
##較單純!# custom_Shape_get_poly()2.pyimport turtle
T=turtle.Turtle()T.home()
T.begin_poly()
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.fd(50)
T.lt(90)
T.end_poly()
#myPoly=T.get_poly()
turtle.register_shape("myShape",T.get_poly())
T.shape("myShape")T.turtlesize(5)
T.color('red')
T.forward(100)

以下測試第二個例子 雪花形狀

  1. 產生單一一個雪花形狀,
  2. 再用 get_poly(), register_shape() 的方法, 定義此雪花為一個新的海龜形狀 “myShape”,
  3. 再令當下海龜的形狀是此新的雪花形狀 T.shape("myShape")

以下, 我們先畫出一個雪花形狀,
再用他註冊一個新的海龜形狀: 只要把產生雪花的函數 snowflake() 放在T.begin_poly(), T.end_poly() 中間就可以,
再用 turtle.register_shape("myShape", T.get_poly()), 即完成註冊新的海龜形狀,
再將海龜形狀令為此新定義之形狀 “myshape”
T.shape("myShape")

T.begin_poly()
snowflake(40, 0, 0, "red", 8)
T.end_poly()
turtle.register_shape("myShape", T.get_poly())
T.shape("myShape")
  1. 以下, 我們先畫出一個雪花形狀, 先把 snowflake() 的程式碼寫好.
  2. 只要把產生雪花的函數 snowflake() 放在T.begin_poly(), T.end_poly() 中間就可以:
T.begin_poly()
snowflake(40, 0, 0, "red", 8)
T.end_poly()
  1. 再用他註冊一個新的形狀,
turtle.register_shape("myShape", T.get_poly())
  1. 再令當下海龜的形狀是此新的海龜形狀
T.shape("myShape")

# -*- coding: utf-8 -*-# set custom shape 20160617
#Turtle 24.1. Turtle graphics — Python v3.3# Tested by Prof. P-J Lai MATH NKNU 20210103
##24.1.3.7. Special Turtle methods
##begin_poly()
##end_poly()
##register_shape("myshape",get_poly())
##T.shape("myShape")
##較單純!# custom_Shape_get_poly()2.pyimport turtle
T=turtle.Turtle()turtle.bgcolor("cyan")
T.speed(0)# create one branch of the snowflake
def branch(size):for i in range(3):T.left(45)for i in range(3):T.forward(size/3)T.backward(size/3)T.right(45)T.left(90)T.backward(size/3)# create a function to create different size snowflakes
def snowflake(size, x, y, color, petalNumber):
# move the pen into starting positionT.penup()T.goto(x,y)T.color(color)T.pendown()# draw branch petalNumber times to make a snowflakefor i in range(petalNumber):T.fd(size)branch(size)   T.left(360/petalNumber)T.home()
T.begin_poly()
snowflake(40, 0, 0, "red", 8)
T.end_poly()
turtle.register_shape("myShape", T.get_poly())
T.shape("myShape")#T.turtlesize()
T.color('red')
T.forward(200)

第二種方法 turtle.Shape("compound") 的方法

>>> import turtle
>>> T=turtle.Turtle()
>>> s=turtle.Shape("compound")
>>> poly1=((0,0),(10,0),(10,15),(0,15))
>>> s.addcomponent(poly1,"red","blue")
>>> turtle.register_shape("myshape",s)
>>> T.shape("myshape")
>>> T.fd(200)

第三種方法 screen.register_shape("turtle.gif") 的方法

採用圖片法:

>>> screen.register_shape("turtle.gif")

Note Image shapes do not rotate when turning the turtle, so they do not display the heading of the turtle!

第四種方法 screen.register_shape("triangle", ((5,-3), (0,5), (-5,-3))) 的方法

name is an arbitrary string and shape is a tuple of pairs of coordinates: Install the corresponding polygon shape.

>>> screen.register_shape("triangle", ((5,-3), (0,5), (-5,-3)))

以下測試:

注意: 是以 turtle 當下的方向決定 x 軸的方向,
以下, 20 是對海龜的 y 方向的值
因為 turtle 預設是往東, 所以上圖長方形是水平的躺

# -*- coding: utf-8 -*-# set custom shape 20160617
#Turtle 24.1. Turtle graphics — Python v3.3# Tested by Prof. P-J Lai MATH NKNU 20210103# custom_Shape_get_poly().pyimport turtle
T=turtle.Turtle()# 注意, 是以 turtle 當下的方向決定 x 軸的方向,
# 以下, 20 是對海龜的 y 方向的值
# 因為  turtle 預設是往東, 所以長方形是水平的躺
poly=((0,0),(10,0),(10,20),(0,20))turtle.register_shape("myshape",poly)T.shape("myshape")T.turtlesize(5)
T.color('red')
T.forward(100)

海龜蓋印 (依照當前的的形狀)

可以使用 stamp() 指令, 在當下海龜該地點留下一個與海龜當下形狀一模一樣的烏龜圖形(像蓋章的效果), 會有一個id指定,

clearstamp(id) # 將編號為id之蓋章消除
clearstamps(), 刪除全部 stamp,
clearstamps( n ) 刪除前 n 個 stamp


調控動畫的速度

speed(1) 最慢
speed(10) 快
speed(0) 最快

speed(0) 對複雜圖形還是太慢,
需使用
turtle.tracer(n,t), n 每隔n幅才播出, t milliseconds 是 delay
預設是 turtle.tracer(1, 10),
turtle.tracer(0,0) 是瞬間畫出, 最快, 但是沒有動畫效果

>>> import turtle
>>> help('turtle.tracer')
Help on function tracer in turtle:turtle.tracer = tracer(n=None, delay=None)Turns turtle animation on/off and set delay for update drawings.Optional arguments:n -- nonnegative  integerdelay -- nonnegative  integerIf n is given, only each n-th regular screen update is really performed.(Can be used to accelerate the drawing of complex graphics.)Second arguments sets delay value (see RawTurtle.delay())Example:>>> tracer(8, 25)>>> dist = 2>>> for i in range(200):...     fd(dist)...     rt(90)...     dist += 2

打開 IDLE 編輯器 執行一連串的程式指令(草稿檔)

IDLE 是 Python 的小作家,
IDLE 編輯器可以在此定義較複雜的函數, 或是一連串的程式指令, 會比在consola一行一行輸入較方便, 也易於除錯, 在 Matlab 的書裡稱這種為草稿檔, 副檔名就是 .py.

可以打開 IDLE 左上方 File/New File, 產生一個空白的類似小作家編輯器, 輸入以下 adder() 定義加法函數的程式碼, 再按 F5 執行編譯, 會要求存此草稿檔, 你可以指定在例如存在, 電腦的桌面, 等,

正規的函數定義法 def, return

def, return 是關鍵字, adder 是自己取的名稱

def adder(x, y):
(縮排空4格) return x + y

# Ref: 官網的文件: python-3.3.2-docs-pdf-a4def adder(x, y):return x + y

再在 IDLE consola 畫面下 adder(2,3) 等指令, 環境就認得這個 adder() 的指令了:

>>> adder(2,3)
5

return 是關鍵字, 代表返回某值,
一個 函數的定義, 也可以沒有 return, 只是做某些動作.


  • 以下可以等進階時再細看

匿名函數 lambda function

以上用 def 定義加法函數,
lambda function 的定義法為:
adder = lambda x, y: x+y

超過1行就用 def 的方法
print_assign = lambda name, value : name + ’=’ + str(value)

高階函數: 函數可以輸入函數

Q: 函數可以輸入函數為引數嗎? (有時稱為"高階函數", “泛函函數”)
Ans: 可以, 例如,
先定義一個函數:

def test(f,x):return f(x)

這個函數會把輸入的函數 f, 求值在 x, 返回 f(x),
以下用 lambda function 的方法用在 f 的位置,
也就是定義一個臨時的拋物線函數 lambda x: x**2
再輸入

>>> test(lambda x: x**2,3)
9

就會回 x2x^2x2 函數作用在 3 的值, 就是 9.

高階函數: 函數可以返回函數

Q: 函數可以返回函數嗎?
Ans; 可以

# By P-J Lai MATH NKNU 20211227def test():return lambda x: x**2print(test()(5))def test(n):return lambda x: x**nprint(test(2)(5))print(test(3)(5))##run result:
##>>>
##=============== RESTART: C:/Users/user/Desktop/return_function.py ==============
##25
##25
##125

執行結果:

>>>
=============== RESTART: C:/Users/user/Desktop/return_function.py ==============
25
25
125

Ref: http://shouce.jb51.net/Python_jj/decorators/return_func_in_func.html
http://shouce.jb51.net/Python_jj/index.html

函數的輸入引數可以有預設值

Q: 函數的輸入引數可以有預設值嗎?
Ans: 可以,

   def test( a=10, b):return a+b

函數的輸入引數個數可以不確定

Q: 函數的輸入引數個數可以不確定嗎?
Ans: 可以輸入 list, 或是
可以使用 不確定參數數量 *foos,

不確定keywords數量則使用 **foos
foos為自己取的名稱.

5.5.1 注意函數的局部變數 local variable 與全域變數 global variable 之互動狀況

簡而言之: 如果內部與外部有同名之變數,

  • 內部同名變數沒有賦值, 只有讀取他的值, 此時會視他為與外部變數同一個, 取用外部變數的值,
  • 如果內部同名變數有賦值, 或做更改值的動作, 此時會視他為內部變數(屏蔽掉外部變數), 此時對他做的動作與, 外部同名變數無關.

也就是, 在函數內部, 對同名之變數做任何動作, 都不會改動到外部同名變數之值

函數的局部變數 local variable 與全域變數 global varibale, 與一般語言 C, Java 等類似, 只要注意至少有一點與 C 不同:

注意 Python 與 C 不同之處, function 內無法更改 外部的全域變數,
例如迷宮之例子, 全域變數 maze, success,
參考本系列博文: 從 Logo 海龜繪圖 學習 Python - 高中彈性課程系列 11 用 turtle 呈現演算法之執行動作, https://blog.csdn.net/m0_47985483/article/details/111172062 link

必須在 function 內, 再加一個 global maze, 才能更改 maze.

如果沒宣告, 會無法更改 全域變數 maze, success 之值, 會出現以下之 error:

>>>
,,,,,
UnboundLocalError: local variable 'success' referenced before ass
  • 以上可以等進階時再細看

python 函数传参數是否会改变函数外部参数的值

簡而言之:

  • 如果你傳的是 数字、字符或者元组, 就是傳值引用, 不會改動到原來外部的變數值.
  • 如果你傳的是字典或者列表, 就會改動到原來外部的字典或者列表的值, 所以傳 list 進入函數內部要小心.

Ref: python:函数传参是否会改变函数外参数的值, https://blog.csdn.net/liuxiao214/article/details/81673093 link
這篇提到:
Python不允许程序员选择采用传值还是传引用。Python参数传递采用的肯定是“传对象引用”的方式。实际上,这种方式相当于传值和传引用的一种综合。如果函数收到的是一个可变对象(比如字典或者列表)的引用,就能修改对象的原始值——相当于通过“传引用”来传递对象。如果函数收到的是一个不可变对象(比如数字、字符或者元组)的引用,就不能直接修改原始对象——相当于通过“传值”来传递对象。

当人们复制列表或字典时,就复制了对象列表的引用同,如果改变引用的值,则修改了原始的参数。
————————————————
版权声明:本文为CSDN博主「夏洛的网」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liuxiao214/article/details/81673093

另外如果程式碼有輸入外部檔案內容的動作

則此檔案, 最簡單的做法就是, 把外部資料集等檔案草稿檔放在同一資料夾內
例如,
假設我們打開 Python IDLE, 或是用 Anaconda Jupter Notebook,PyCharm等,
新增一個草稿檔, 輸入程式碼, 先存在桌面
Python 會自動記錄, 現在桌面就是你目前, 草稿檔的預設資料夾,
然後把例如下載的 Titanic鐵達尼號 的資料集, 也放在桌面, Python IDLE就會找到 下載的資料集.

(注意 Anaconda Jupter Notebook 預設的當前工作資料夾是在較深處, 要查一下,
而 Python IDLE, 你只要把 草稿檔存在例如 桌面, Python 會自動記錄, 現在桌面就是你目前, 草稿檔的預設資料夾,)

例如以下程式碼草稿檔, 先存在桌面, Titanic鐵達尼號 的資料集, 也放在桌面, 執行程式碼, 就會輸入 Titanic 的資料存在 test 這個變數裡:

##train = pd.read_csv("../input/train.csv")
##test    = pd.read_csv("../input/test.csv")train = pd.read_csv("./train.csv")
test    = pd.read_csv("./test.csv")full = train.append( test , ignore_index = True )
titanic = full[ :891 ]del train , testprint ('Datasets:' , 'full:' , full.shape , 'titanic:' , titanic.shape)

輸出:

>>>
Datasets: full: (1309, 12) titanic: (891, 12)

函數, 迴圈, 程式的終結退出 return, break, quit(), exit(), sys.exit(), os.exit()

  • 如果是在一個函數內的結束, 就是使用 return,
  • 如果是迴圈內, break 只能中斷該層的迴圈, 如果有兩層或三層迴圈, 外層的迴圈還是會繼續進行, 初學者在這裡會容易出錯, 要特別小心!
  • 如果是整個程式, .py 檔要結束, 就要使用 quit(), exit(), sys.exit(), os.exit() 等.

所謂模組 module 就是 副檔名.py 的檔案.

module 模組, 是一個 .py 檔案, 裏面是一堆指令或是子程式={ function, function,}

package 套件, 是由一堆 module 構成={ module, modules,}, 也就是一堆 .py 檔案構成的資料夾.

__name__ ==“__main__” 的含意

Ref: https://www.itread01.com/content/1548146531.html

模組中的__name__屬性:

每個模組都有一個__name__屬性,當其值為 “main” 時,表明該模組自身在執行,

否則是被當做模組引入,此時值為模組的名字

作用:模組就是一個可執行的 python檔案 ( .py 檔),一個模組被另一個模組引入import,想讓被引入的模組, 只有在他的函數被呼叫時才執行, 而他的其他程式碼不自動執行(只編譯待命),我們可以用__name__屬性來使程式隱藏該塊內碼,
當自身執行時(不是被引入import的狀態),才會執行該塊程式碼.

一般程式的起始位置都是從 __name__ ==“__main__” 開始.


recursive 遞迴函數

一般程式語言, recursive 遞迴函數的寫法, 就是有
函數自己呼叫自己
的結構.
請查本系列:
Logo 海龜繪圖學習 Python - 7 遞歸 recursive - 高中彈性課程系列 link
有關遞迴函數的寫法


5.5.1 注意函數的局部變數 local variable 與全域變數 global variable 之互動狀況

函數的局部變數 local variable 與全域變數 global varibale, 與一般語言 C, Java 等大致類似, 只要注意至少有一點與 C 不同:

在函數內部定義的變數, 都是局部變數, 出了這個函數就沒有定義,
在所有函數外部定義的變數, 都是全域變數,每個函數都可讀取, 不能改值 (要改, 需在函數內部宣告 global a(某全域變數名) )
Ref: 輕鬆學Python 3 零基礎彩色圖解
https://sites.google.com/site/ezpythoncolorcourse/globalandlocalvariable link

————————————————
以下可以等進階時再細看

.py檔與 .py檔之間的全域變數共享, 作法較複雜, 可以參考:
python — 怎麼在兩個檔案之間分享全域變數
https://medium.com/@kweisamx0322/python-%E6%80%8E%E9%BA%BC%E5%9C%A8%E5%85%A9%E5%80%8B%E6%AA%94%E6%A1%88%E4%B9%8B%E9%96%93%E5%88%86%E4%BA%AB%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8-8fced72f3550
link
以上可以等進階時再細看

Ref:https://blog.csdn.net/m0_47985483/article/details/109522858 lik

只要注意至少有一點與 C 不同:

注意 Python 與 C 不同之處, function 內無法更改 外部的全域變數, 只能讀取,
例如迷宮之例子, 全域變數 maze, success,
參考本系列博文: 從 Logo 海龜繪圖 學習 Python - 高中彈性課程系列 11 用 turtle 呈現演算法之執行動作, https://blog.csdn.net/m0_47985483/article/details/111172062 link

如果 function 內要更改 外部的全域變數, 例如想要 更改 外部的全域變數 maze,
必須在 function 內, 再加一個宣告 global maze, 才能更改 maze.


補捉異常

函數的輸入, 必須預期, 使用者可能會輸入不預期(不合法) 的內容, 例如, 應該要輸入整數, 但是使用者輸入 1/2 分數, sqrt(2) 無理數 等,
如何防止這類事情?
搜尋: stable codes 穩健的程式碼
使用
try:
縮排 指令
except:
縮排 發生異常時處理之程動作

語法
或用 aasert (斷言) 會較簡潔:
assert 真假值條件, ‘字串’

查 part2, 5.1 Python recursive 遞迴函數的寫法


20201107 By P-J Lai MATH NKNU

注意, 背景色, bgcolor('black') 的設定

如引入方式是,
import turtle
則用 turtle.bgcolor('black')
不能用 T.bgcolor(‘black’)

如引入方式是,
from turtle import *
則用 bgcolor('black')


本課程用到物件導向的部分內容

請參考
從 Logo 海龜繪圖 學習 Python - 高中彈性課程系列 9 Python 物件導向介紹 link
10. Python 物件導向介紹

Ref: Cory Althoff, The self-taught programmer, Python 編程無師自通,
gitHub上有原始碼, https://github.comcalthoff link

tstp/part2, ch12 paradigm編程泛式之後段,
tstp/part2, ch13 the_four_pillars_of_oop 物件導向之四大支柱,
tstp/part2, ch14 more_object_oriented_programming 更多物件導向,
以上三章之codes, 有物件導向的說明程式碼

洪錦魁, Python 王者歸來, ch12 類, 清華大學出版, 2019.

以上這兩本書的講解, 較簡單易懂, 初學者可以很快了解.
但是較進階的概念, 可以再自行閱讀較完整的資料, 例如
Dusty Phillips, Pyhton3 object oriented programming, Pyhton3 面對對象編程, 電子工業.

另外, 對初學者, 寫得較深入又不致太繁瑣是以下這本:
AI Sweigart, Beyond the basic stuff with Pyhton,
中譯本: H&C譯, Python 功力提升的樂趣, 基峰出版, 2021.

如何讓多隻海龜一起移動

在12.3 海龜繪圖模擬 紫雨無聲落下 藝術
(5.13 Project: 讓多隻海龜同時移動 模擬 starfield 星際大戰的光速飛行場景)

用到 “如何讓多隻海龜一起移動”
我們查了網路上的解法, 在 stackoverflow 上, 提供3種解法
注意以下三種方法, threading 還是只使用單顆 CPU, 在硬體上並沒有真正平行執行,
method 1. 每隻都動一小段, 換下一隻
method 2. 用 ontimer()
method 3. 用 thread 多線程


method 1. 只需改寫 for loop, 每隻都動一小段, 換下一隻動, 較容易實現


method 3. 用 threading 多線程模組, 我們參考
洪錦魁, Python 王者歸來, ch30 多任務線程與多線程,

但是 threading 還是只使用單顆 CPU, 在硬體上並沒真正平行執行, 只是把時間切成很小段輪流執行, 讓執行者以為是平行再跑, 確實是可以讓海龜同時動, 但是效能並沒有改善, 只是程式碼看起來較有學問, 閱讀與維護較容易, 也較適合移植到其他有平行處理的程式語言上.

必須用 multiprocessing, subproces, 才會用多個 kernel, 才有真正平行硬體加速的效果!
Ref: 在 21Python sec15.2 才看到, 線程 threading只使用一個處理器,
進程 multiprocessing, subprocess 才會用多個 kernel

或是 Slatkin 那本書 sec41, 建議使用 concurrent.futures 模組的 ProcessPoolExcutor 類, 語法較簡單, 可以真正的平行執行 一些特定類型的程式, isolated, high-leverage 類型的任務, 意指, 父行程與子行程間只須轉移少量資料, 就能進行大量計算的那種類型的任務, 例如 最大公因數演算法, 還有許多數學演算法也都適合,

Ref: Brett Slatkin, Effective Python, sec41, 中譯本, 基峯出版.

本課程用到多執行緒(多線程 threading 模組)的部分內容

注意: 線程 threading只使用一個處理器
必須用 multiprocessing, subproces, 才會用多個 kernel

Ref: 在 21 學通 Python sec15.2 才看到, 線程 threading只使用一個處理器,
進程 multiprocessing, subprocess 才會用多個 kernel

第一個最基本例子 產生一個 (副線程, 主線程之外的第二個) thread

  1. import threading
  2. 先定義一個 函數, wakeUp()
  3. 產生一個 (副線程, 主線程之外的第二個) thread, 負責執行 wakeUp():
    threadFoo = threading.Thread(target=wakeUp)
  4. (副) thread 開始: threadFooj.start()
# test By Prof. P-J Lai MATH NKNU 20201122
# test Pyhton threads# ref: 洪錦魁, ch30 多任務線程與多線程
import threading, timedef wakeUp():print("threadObj線程開始")time.sleep(10)print(" 生日快樂! ")print("threadObj線程結束")print("主線程階段1")
threadObj = threading.Thread(target=wakeUp)
threadObj.start()
time.sleep(1)
print("主線程階段2")##= RESTART: C:\Users\user\Desktop\test_Pyhton_thread.py
##主線程階段1
##threadObj線程開始
##主線程階段2
##>>>  生日快樂!
##threadObj線程結束##   | 主線程
##   |-----------------------分出第二個線程
##   |--------------------------|
##  print("主線程階段1")-------print("threadObj線程開始")
##   |--------------------------|
##   |--------------------------|
##  time.sleep(1) ----------time.sleep(10)

第二個最基本例子: 副線程的函數 wakeUp(), 可以輸入參數(引數 arguments):

def wakeUp(name, blessingWord):
,
threadObj = threading.Thread(target=wakeUp, args=['新莊高中', '生日快樂'])

# test By Prof. P-J Lai MATH NKNU 20201122
# test Pyhton threads arguments# ref: 洪錦魁, ch30 多任務線程與多線程
# 參數的傳遞import threading, timedef wakeUp(name, blessingWord):print("threadObj線程開始")time.sleep(10)print(name," ",blessingWord)print("threadObj線程結束")print("主線程階段1")threadObj = threading.Thread(target=wakeUp, args=['新莊高中', '生日快樂'])
threadObj.start()
time.sleep(1)
print("主線程階段2")##= RESTART: C:\Users\user\Desktop\test_Pyhton_thread.py
##主線程階段1
##threadObj線程開始
##主線程階段2
##>>> 新莊高中   生日快樂
##threadObj線程結束##   | 主線程
##   |---------------------分出第二個線程
##   |--------------------------|
##  print("主線程階段1")-------print("threadObj線程開始")
##   |--------------------------|
##   |--------------------------|
##  time.sleep(1) ----------time.sleep(10)

Python list 的指令

參考官網的手冊
Ref: https://docs.python.org/zh-tw/3/tutorial/index.html [link](https://docs.python.org

官網的手冊 3.1.3. List(串列)

最入門的說明
Python 理解數種複合型資料型別,用來組合不同的數值。當中最多樣變化的型別為 list,可以寫成一系列以逗號分隔的數值(稱之元素,即 item),包含在方括號之中。List 可以包合不同型別的元素,但通常這些元素會有相同的型別:

>>>
>>> squares = [1, 4, 9, 16, 25]
>>> squares
[1, 4, 9, 16, 25]
如同字串(以及其他內建的 sequence 型別),list 可以被索引和切片 (slice):>>>
>>> squares[0]  # indexing returns the item
1
>>> squares[-1]
25
>>> squares[-3:]  # slicing returns a new list
[9, 16, 25]所有切片操作都會回傳一個新的 list ,包含要求的元素。這意謂著以下這個切片回傳了原本 list 的 淺複製 :>>>
>>> squares[:]
[1, 4, 9, 16, 25]
List 對支援如接合 (concatenation) 等操作:>>>
>>> squares + [36, 49, 64, 81, 100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
不同於字串是 immutable,list 是 mutable 型別,即改變 list 的內容是可能的:>>>
>>> cubes = [1, 8, 27, 65, 125]  # something's wrong here
>>> 4 ** 3  # the cube of 4 is 64, not 65!
64
>>> cubes[3] = 64  # replace the wrong value
>>> cubes
[1, 8, 27, 64, 125]你也可以在 list 的最後加入新元素,透過使用 append() 方法 (method)(我們稍後會看到更多方法的說明):>>>
>>> cubes.append(216)  # add the cube of 6
>>> cubes.append(7 ** 3)  # and the cube of 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343]也可以對 slice 賦值,這能改變 list 的大小,甚至是清空一個 list:>>>
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']
>>> # now remove them
>>> letters[2:5] = []
>>> letters
['a', 'b', 'f', 'g']
>>> # clear the list by replacing all the elements with an empty list
>>> letters[:] = []
>>> letters
[]內建的函式 len() 亦可以作用在 list 上:>>>
>>> letters = ['a', 'b', 'c', 'd']
>>> len(letters)
4也可以嵌套多層 list (建立 list 包含其他 list),例如:>>>
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b'

官網的手冊 5.1. 進一步了解 List(串列)

Ref: https://docs.python.org/zh-tw/3/tutorial/datastructures.html#more-on-lists link
5. 資料結構
這個章節將會更深入的介紹一些你已經學過的東西的細節上,並且加入一些你還沒有接觸過的部分。

5.1. 進一步了解 List(串列)
List(串列)這個資料型態,具有更多操作的方法。下面條列了所有關於 list 物件的 method:

list.append(x)
將一個新的項目加到 list 的尾端。等同於 a[len(a):] = [x]。

list.extend(iterable)
將 iterable(可疊代物件)接到 list 的尾端。等同於 a[len(a):] = iterable。

list.insert(i, x)
將一個項目插入至 list 中給定的位置。第一個引數為插入處前元素的索引值,所以 a.insert(0, x) 會插入在 list 首位,而 a.insert(len(a), x) 則相當於 a.append(x)。

list.remove(x)
刪除 list 中第一個值等於 x 的元素。若 list 中無此元素則會觸發 ValueError。

list.pop([i])
移除 list 中給定位置的項目,並回傳它。如果沒有指定位置, a.pop() 將會移除 list 中最後的項目並回傳它。(在 i 周圍的方括號代表這個參數是選用的,並不代表你應該在該位置輸入方括號。你將會常常在 Python 函式庫參考指南中看見這個表示法

list.clear()
刪除 list 中所有項目。這等同於 del a[:]。

list.index(x[, start[, end]])
回傳 list 中第一個值等於 x 的項目之索引值(從零開始的索引)。若 list 中無此項目,則丟出 ValueError 錯誤。

引數 start 和 end 的定義跟在 slice 表示法中相同,搜尋的動作被這兩個引數限定在 list 中特定的子序列。但要注意的是,回傳的索引值是從 list 的開頭開始算,而不是從 start 開始算。

list.count(x)
回傳 x 在 list 中所出現的次數。

list.sort(*, key=None, reverse=False)
將 list 中的項目排序。(可使用引數來進行客製化的排序,請參考 sorted() 部分的解釋)

list.reverse()
將 list 中的項目前後順序反過來。

list.copy()
回傳一個淺複製 (shallow copy) 的 list。等同於 a[:]

以下是一個使用到許多 list 物件方法的例子:

>>>
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4)  # Find next banana starting a position 4
6
>>> fruits.reverse()
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> fruits.append('grape')
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
>>> fruits.sort()
>>> fruits
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
>>> fruits.pop()
'pear'

你可能會注意到一些方法,像是 insert、remove 或者是 sort,並沒有印出回傳值,事實上,他們回傳預設值 None 1。這是一個用於 Python 中所有可變資料結構的設計法則

另外你可能也會發現,不是所有資料都可以被排序或比較。例如,[None, ‘hello’, 10] 就不可排序,因為整數不能與字串比較,而 None 不能與其他型別比較。有些型別根本就沒有被定義彼此之間的大小順序,例如,3+4j < 5+7j 就是一個無效的比較。

5.1.1. 將 List 作為 Stack(堆疊)使用

List 的操作方法使得它非常簡單可以用來實作 stack(堆疊)。Stack 為一個遵守最後加入元素最先被取回(後進先出,“last-in, first-out”)規則的資料結構。你可以使用方法 append() 將一個項目放到堆疊的頂層。而使用方法 pop() 且不給定索引值去取得堆疊最上面的項目。舉例而言:

>>>
>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> stack.pop()
5
>>> stack
[3, 4]

5.1.2. 將 List 作為 Queue(佇列)使用

我們也可以將 list 當作 queue(佇列)使用,即最先加入元素最先被取回(先進先出,“first-in, first-out”)的資料結構。然而,list 在這種使用方式下效率較差。使用 append 和 pop 來加入和取出尾端的元素較快,而使用 insert 和 pop 來插入和取出頭端的元素較慢(因為其他元素都需要挪動一格)。

如果要實作 queue,請使用 collections.deque,其被設計成能快速的從頭尾兩端加入和取出。例如:

>>>
>>> from collections import deque
>>> queue = deque(["Eric", "John", "Michael"])
>>> queue.append("Terry")           # Terry arrives
>>> queue.append("Graham")          # Graham arrives
>>> queue.popleft()                 # The first to arrive now leaves
'Eric'
>>> queue.popleft()                 # The second to arrive now leaves
'John'
>>> queue                           # Remaining queue in order of arrival
deque(['Michael', 'Terry', 'Graham'])

5.1.3. List Comprehensions(串列解析式)

List comprehension(串列解析式, 串列綜合運算)讓你可以用簡潔的方法創建 list。

舉例來說,假設我們要創建一個「平方的 list」, 以下是使用 List comprehension 的方式 :

>>> [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

或是產生一個 奇數平方的串列, 後面可以加上 if :

>>> [x**2 for x in range(10) if x%2==1]
[1, 9, 25, 49, 81]

常見的應用是基於一個序列或 iterable(可疊代物件),將每一個元素經過某個運算的結果串接起來成為新的 list,或是創建一個子序列,其每一個元素皆滿足一個特定的條件。

以下是使用 for loop 的風格:

>>> squares = []
>>> for x in range(10):
...     squares.append(x**2)
...
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

注意這是創建(或覆寫)一個變數叫 x,其在迴圈結束後仍然存在。我們可以這樣產生平方串列而不造成任何 side effects(副作用), 使用 map 結合 lambda 函數:

squares = list(map(lambda x: x**2, range(10)))

已經比較簡潔了, 但是比起 List comprehension(串列解析式), 還是List comprehension(串列解析式) 更簡潔和易讀:
squares = [x**2 for x in range(10)]

如果是 產生一個奇數平方的串列 的例子, 使用 map 結合 lambda 函數, 再用 filter 把偶數過濾掉 :
oddSquares=list(map(lambda x: x**2, filter(lambda x: x%2==1, range(10))))

>>> oddSquares=list(map(lambda x: x**2, filter(lambda x: x%2==1, range(10))))
>>> oddSquares
[1, 9, 25, 49, 81]

則覺得以上指令相當繁複, 不好閱讀, 遠比不上
[x**2 for x in range(10) if x%2==1]
簡單直接!


一個 list comprehension 的組成,是在一對方括號內,放入一個 expression(運算式)、一個 for 子句、再接著零個或多個 for 或 if 子句。結果會是一個新的 list,內容是在後面的 for 和 if 子句情境下,對前面運算式求值的結果。例如,這個 list comprehension 組合了兩個 list 中彼此相異的元素:

>>>
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
而它就等於:>>>
>>> combs = []
>>> for x in [1,2,3]:
...     for y in [3,1,4]:
...         if x != y:
...             combs.append((x, y))
...
>>> combs
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
注意 for 和 if 在這兩段程式裡的順序是相同的。如果 expression 是一個 tuple(例如上面例子中的 (x, y)),它必須加上括號:>>>
>>> vec = [-4, -2, 0, 2, 4]
>>> # create a new list with the values doubled
>>> [x*2 for x in vec]
[-8, -4, 0, 4, 8]
>>> # filter the list to exclude negative numbers
>>> [x for x in vec if x >= 0]
[0, 2, 4]
>>> # apply a function to all the elements
>>> [abs(x) for x in vec]
[4, 2, 0, 2, 4]
>>> # call a method on each element
>>> freshfruit = ['  banana', '  loganberry ', 'passion fruit  ']
>>> [weapon.strip() for weapon in freshfruit]
['banana', 'loganberry', 'passion fruit']
>>> # create a list of 2-tuples like (number, square)
>>> [(x, x**2) for x in range(6)]
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
>>> # the tuple must be parenthesized, otherwise an error is raised
>>> [x, x**2 for x in range(6)]File "<stdin>", line 1, in <module>[x, x**2 for x in range(6)]^
SyntaxError: invalid syntax
>>> # flatten a list using a listcomp with two 'for'
>>> vec = [[1,2,3], [4,5,6], [7,8,9]]
>>> [num for elem in vec for num in elem]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
List comprehensions 可以含有複雜的 expression 和巢狀的函式:>>>
>>> from math import pi
>>> [str(round(pi, i)) for i in range(1, 6)]
['3.1', '3.14', '3.142', '3.1416', '3.14159']
5.1.4. 巢狀的 List Comprehensions
在 list comprehesion 中開頭的 expression 可以是任何形式的 expression,包括再寫一個 list comprehension。考慮以下表示 3x4 矩陣的範例,使用 list 包含 3 個長度為 4 的 list :>>>
>>> matrix = [
...     [1, 2, 3, 4],
...     [5, 6, 7, 8],
...     [9, 10, 11, 12],
... ]
以下的 list comprehesion 會將矩陣的行與列作轉置:>>>
>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
如同我們在上一節看到的,此巢狀的 list comprehension 會依據後面的 for 環境被求值,所以這個例子就等於:>>>
>>> transposed = []
>>> for i in range(4):
...     transposed.append([row[i] for row in matrix])
...
>>> transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
而它也和這一段相同:>>>
>>> transposed = []
>>> for i in range(4):
...     # the following 3 lines implement the nested listcomp
...     transposed_row = []
...     for row in matrix:
...         transposed_row.append(row[i])
...     transposed.append(transposed_row)
...
>>> transposed
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
在實際運用上,我們傾向於使用內建函式 (built-in functions) 而不是複雜的流程控制陳述式。在這個例子中,使用 zip() 函式會非常有效率:>>>
>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
關於星號的更多細節,請參考拆解引數列表(Unpacking Argument Lists)。

stack 堆疊, 先進後出,在 Python 中, 可以用 list

stack 堆疊, 在 Python 中, 用 list 的容器,
例如 A = [ ]
A.append( a ) 從後方加入a
A.pop( a ) 從後方拍出 a
就完成 先進後出 first in first out (FIFO) 的效果,
此種容器就是所謂的 堆疊 stack.

例子可以參考 本系列
從 Logo 海龜繪圖 學習 Python - 高中彈性課程系列 11 用 turtle 呈現演算法之執行動作

按先後走過之順序 印出第一個找到之路徑 立即結束 (用堆疊改寫 ‘最基本的寫法’)
參考自河西朝雄 Dr30_1.c
以下增加一個
solQueue = [ ]
來存放第一個找到之路徑,
列印路徑時, 從此 solQueue 逐項印出, 就會是按先後順序印出.

queue 隊列, , 先進先出, 在 Python 中, 可以用 deque

Ref: David Kopec, Classic Computer Science Problems in Python, Manning, 經典電腦問題解析使用 Python, 基峰.
使用 collection module 中的 deque 指令

官網的說明:
tutorial_5.1.2 Using Lists as Queues_python-3.6.5-docs-pdf-a4
指出用 list 作 queue 效率較低,
可以使用 collections.deque

官網的例子:

>>> from collections import deque
>>> d = deque('ghi')   # make a new deque with three items
>>> for elem in d:     # iterate over the deque's elements
...     print(elem.upper())
G
H
I
>>> d.append('j')          # add a new entry to the right side
>>> d.appendleft('f')      # add a new entry to the left side
>>> d                     # show the representation of the deque
deque(['f', 'g', 'h', 'i', 'j'])>>> d.pop()      # return and remove the rightmost item
'j'
>>> d.popleft()      # return and remove the leftmost item
'f'

Python 風格的寫法與功能

我們參考:

  • AI Sweigart, Beyond the basic stuff with Pyhton,
    中譯本: H&C譯, Python 功力提升的樂趣, 基峰出版, 2021.
  • Bret Slatkin, Effective Python, 中譯本, 基峰出版.

Python 等號的多重指定

>>> a = b = c = d = 10
>>> a,b,c,d
(10, 10, 10, 10)

允許多個變量同時指定不同的值

>>> a, b, c, d = 1, 2, 3, 4
>>> a,b,c,d
(1, 2, 3, 4)

適當使用 串列解析式代替 for 迴圈

如前面介紹的 List Comprehension(串列解析式).

使用 zip 來平行處理迭代器

References

參考資料總表

  • https://www.scribd.com/document/92940122/
    SevenWaysToUseTurtle-PyCon2009
    link

  • 官網 turtle module 手冊: Turtle graphics-Python 3.8 (舊版是24.1節).pdf, https://docs.python.org/3/library/turtle.html
    link

  • 有關 外部模組的說明可以參考: 用 Python+Numpy+scipy 執行 Matlab 的矩陣計算 1 Python科學計算第三方庫, 原生指令, 內建模組, 外部模組 link

  • Cory Althoff, The Self-Taught Programmer, Hodgman Literary LLC, 2017.
    (簡版中文: Python編程無師自通)

  • 用 Logo繪製之板塊藝術, 參考自 BFOIT
    Introduction to Computer Programming
    ref: http://guyhaas.com/bfoit/itp/Operators.html
    link)

  • https://www.programiz.com/python-programming/keyword-list
    link
    這個站有對每個 keyword 個別說明

  • https://www.w3schools.com/python/python_ref_keywords.asp
    這個站有對每個 keyword 個別說明
    link

  • Python函數的返回值與嵌套函數 - 每日頭條,
    函數基本解釋, 閉包解釋清楚簡單
    https://kknews.cc/zh-tw/code/ngopzeg.html link

  • 美麗的圖形 https://www.pinterest.com/drnagy18/fonalgrafika1/ link

  • Python带你找回童年的万花尺, http://baijiahao.baidu.com/s?id=1651085589151024260 link

  • 使用python成为藝術家, https://my.oschina.net/u/4531265/blog/4278176 link

  • 等等!等高線居然可以有非凡的藝術氣質?!https://www.getit01.com/p2018041735235656/ link

  • Python——畫一棵漂亮的樱花樹, https://blog.csdn.net/weixin_43943977/article/details/102691392 link
    非常漂亮的樹!

  • 生成式藝術和演算法創作07 L, https://zhuanlan.zhihu.com/p/50712698 link

  • Michael Hansmeyer:塑造不可思议, https://v.youku.com/v_show/id_XNDc4MDM2NzA4.html link

  • https://youtu.be/qtPi0JvmWbs
    Generative Art
    生成藝術暑期工作營
    東南大學建築學院 建築運算與應用研究所

  • Creative Algorithms - Generative Design & Creative Coding Art
    https://youtu.be/Z9NLxrkMWM4

  • (Sher Minn Chong) exploring the beauty of algorithms with generative art - talk
    https://youtu.be/Y1bPsh1mFUI link

  • Sher Minn Chong Make art with JavaScript!
    https://youtu.be/HiCK8e1ElRQ link

  • python图形绘制库turtle中文开发文档及示例大全
    https://blog.csdn.net/A757291228/article/details/105884899 link
    等於把 官網手冊: Turtle graphics-Python 3.8 (舊版是24.1節).pdf, 翻成中文, 非常詳細完整!!

  • 本課程用到物件導向的書(的部分內容)
    – Cory Althoff, The self-taught programmer, Python 編程無師自通,
    gitHub上有原始碼, https://github.comcalthoff link

    tstp/part2, ch12 paradigm編程泛式之後段,
    tstp/part2, ch13 the_four_pillars_of_oop 物件導向之四大支柱,
    tstp/part2, ch14 more_object_oriented_programming 更多物件導向, 以上三章之codes, 有物件導向的說明程式碼

    – 洪錦魁, Python 王者歸來, ch12 類, 清華大學出版, 2019.

    以上這兩本書的講解, 較簡單易懂, 初學者可以很快了解,
    但是較進階的概念, 可以再自行閱讀較完整的資料, 例如
    – Dusty Phillips, Pyhton3 object oriented programming, Pyhton3 面對對象編程, 電子工業.
    另外, 對初學者, 寫得較深入又不致太繁瑣是以下這本:
    – AI Sweigart, Beyond the basic stuff with Pyhton,
    中譯本: H&C譯, Python 功力提升的樂趣, 基峰出版, 2021.

  • Python Object Oriented Programming, https://www.programiz.com/python-programming/object-oriented-programming link

  • 洪錦魁, Python 王者歸來, ch12 類, ch30 多任務線程與多線程, 清華大學出版, 2019.

  • Brett Slatkin, Effective Python, sec41, 中譯本, 基峯出版.
    Slatkin 那本書 sec41, 建議使用 concurrent.futures 模組的 ProcessPoolExcutor 類, 語法較簡單, 可以真正的平行執行 一些特定類型的程式, isolated, high-leverage 類型的任務, 意指, 父行程與子行程間只須轉移少量資料, 就能進行大量計算的那種類型的任務, 例如 最大公因數演算法, 還有許多數學演算法也都適合,

  • 17岁!Kaggle史上最年轻Grandmaster诞生, https://zhuanlan.zhihu.com/p/43616993 link

  • 5小时学会Python 数据分析与展示(2020年版),
    對各個 Python 的使用軟體環境, IDLE, Anaconda 等, 有很清楚的介紹!
    https://www.youtube.com/watch?v=Obbc3pC5_g0 link

  • 呈現碎形樹 “Coding Challenge #14: Fractal Trees - Recursive”
    https://www.youtube.com/watch?v=0jjeOYMjmDU&t=8s, link

  • Generative art in Python: Fractal Trees
    https://youtu.be/EICpm9rnPjE link

  • Generative art in Python: Basic Tiling, https://youtu.be/Cm_SzDlQ2cM link

  • 模擬 starfield 星際大戰的光速飛行場景有聲音 Coding Challenge #1: Starfield in Processing with music
    https://www.youtube.com/watch?v=KWhnilgKM1M link

  • 遞歸如果有動態圖解, 呈現, 例如 呼叫 Fibonacci(5), 需先呼叫 Fibonacci(4) 與 Fibonacci(3),
    且圖形呈現同步對照逐行執行之程式碼, 才驚豔!!!
    中學生應該就可以輕鬆理解,
    發現以下之網站很棒, 包含費氏遞歸及各種 data structure 之動態圖解網站 : https://www.cs.usfca.edu/~galles/visualization/Algorithms.html link

  • 視覺化演算法網站彙總,從此簡單學演算法!(附動圖) https://www.mdeditor.tw/pl/pICL/zh-tw link

  • 劉凌霞等著, 21 學通 Python sec15.2 , 電子工業
    才看到, 線程 threading只使用一個處理器,
    進程 multiprocessing, subprocess 才會用多個 kernel

  • 海龜打點 turtle.dot() 的效果, 可以呈現迷宮或是某些演算法, 走過之位置:
    本篇很好的文章介紹: 從 Python 海龜繪圖初入門到使用遞迴(遞歸) 畫嵌套圖形, 碎形及進階迷宮演算法等:
    数据结构与算法(Python版)——(3)通俗易懂的介绍递归(上),
    https://blog.csdn.net/weixin_45901519/article/details/109456646 link
    這份迷宮程式碼稍微複雜, 把程式碼複製, 存為.py檔, 迷宮初始資料複製到 maze2.txt, 放在同一資料夾下, 就可以執行.

  • David Kopec, Classic Computer Science Problems in Python, Manning, 經典電腦問題解析使用 Python, 基峰.

  • 全域變數輕鬆學Python 3 零基礎彩色圖解
    https://sites.google.com/site/ezpythoncolorcourse/globalandlocalvariable link

  • .py檔與 .py檔之間的全域變數共享, 作法較複雜, 可以參考:
    python — 怎麼在兩個檔案之間分享全域變數,
    https://medium.com/@kweisamx0322/python-%E6%80%8E%E9%BA%BC%E5%9C%A8%E5%85%A9%E5%80%8B%E6%AA%94%E6%A1%88%E4%B9%8B%E9%96%93%E5%88%86%E4%BA%AB%E5%85%A8%E5%9F%9F%E8%AE%8A%E6%95%B8-8fced72f3550
    link


各次上課參考資料

第一次上課參考資料:

  • 賴鵬仁老師講義: python常用Turtle指令-例子講解.doc

  • Turtle的精采示範講義有碎形: SevenWaysToUseTurtle-PyCon2009.pdf
    https://www.scribd.com/document/92940122/SevenWaysToUseTurtle-PyCon2009
    link

  • 官網 turtle module 手冊: Turtle graphics-Python 3.8 (舊版是24.1節).pdf, https://docs.python.org/3/library/turtle.html
    link

  • 唐瑤瑤 / 臺灣大學計算機及資訊網路中心程式設計組程式設計師, Google Colaboratory–適合Python初學者的雲端開發環境, http://www.cc.ntu.edu.tw/chinese/epaper/0052/20200320_5207.html
    link

  • 歡迎使用 Colaboratory (Python 免費線上使用)
    https://colab.research.google.com/notebooks/intro.ipynb
    link

  • 另一個可以免費線上使用Python之站 , https://repl.it/
    link

第3次上課參考資料:

  • 參考以下網站, Dr. Kubeš - Galileo School網址, 下載該網站之上課講義 pdf檔: DrawingGeometricShapes.pdf, 用 Scratch 畫旋轉正多邊形的各種圖案
    Ref: https://sites.google.com/site/matejkubesgalileoschool/computer-science/ict-7ab-8a-scratch/learning-to-program-with-scratch/drawing-geometric-shapes
    link

課程簡介

「Logo海龜繪圖」呈現直觀與幾何之美,利用簡單的重複性可以建構出極為繁複美麗的圖形。

維基百科: ”Logo是一種電腦程式設計語言,在1966年由西摩爾·派普特 Seymour Aubrey Papert (是美國麻省理工學院的數學家。他是人工智慧發展的其中一位先驅。他對智力的觀點主要來自 讓·皮亞傑的影響。他在1968年從LISP語言的基礎裡創立Logo程式語言) 和 Wally Feurzeig 設計,設計 Logo 的初衷是為了向兒童教導電腦程式設計技能”。

本課程帶領同學以 Python 實現 Logo 海龜繪圖,藉由有趣的「海龜繪圖」學會基礎的 Python 程式設計,了解到數學思維設計與程式設計是不可分的,並探討使用到的兩個程式設計的主要元素: 疊代 iterated 與遞迴 recursive,到底疊代與遞迴是同或是不同?

課程大綱:

  1. 初識 Python: 免費之 Python 安裝, 基礎使用
  2. Python 內建的 turtle 模組: 用 Python turtle module 畫圖
  3. 海龜繪圖畫正多邊形: 海龜繪圖畫正多邊形要用到那些數學知識與設計思維? 重複性的工作可否用迴圈 loop的概念完成?
  4. 海龜繪圖畫嵌套正多邊形: 海龜繪圖畫嵌套正多邊形要用到那些數學知識與設計思維? 雙重重複性 的工作可否用巢狀(嵌套) 迴圈 nested loop的概念完成?
  5. 海龜繪圖逆向工程: 網路上看到的美麗海龜繪圖,是否可以自己破解其設計方法?:
  6. 海龜繪圖畫藝術畫: 用海龜繪圖 + Python 成為藝術大師
  7. 遞迴的引入 (1) - 海龜繪圖畫二叉樹碎形: 單用 loop 的概念可以完成碎形的模擬嗎?
    遞迴 recursive 的概念完成二叉樹碎形
  8. 遞迴的引入 (2): 海龜繪圖畫雪花碎形: 用遞迴 recursive 的概念完成碎形雪花
  9. 甚麼? 海龜繪圖也可以 動態 呈現數論的厄爾多拉質數篩去法!: 海龜繪圖呈現數論的厄爾多拉質數篩去法

上課紀錄

第1次上課

20200916 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

目標: Logo海龜繪圖之來由, 安裝 Python, 沒有桌機時線上跑 Python的站, Python 程式基礎介紹, 畫出第一隻 Python海龜

  1. Logo turtle graphics examples - Google圖片 搜尋

  2. Wiki: Logo 程式語言

  3. 觀摩
    高師大數學系學長姐 許竣耀等 Python turtle 隨機碎形樹等作品,
    賴鵬仁老師設計的海龜繪圖 動態 呈現數論的厄爾多拉質數篩去法.

  4. 線上跑 Python:
    Google 的免費雲端跑程式的實驗室: Colab (原本 Python 內建的 turtle module 經過測試無法在Colab使用,
    感謝高師大數學系碩班預研生徐雋崴告知, 必須加裝 ColabTurtle module, 下次上課再詳細講)
    Repl.it (在新莊高中測試, 可能頻寬不足, 延遲太久, 但是在高師大測試OK, 可以跑 Python 內建的 turtle module),
    Pythonista 3 on the App Store,
    QPython 3L - Python for Android - Google Play 應用程式

  5. 桌機或筆電安裝 Python 官方版本,
    官方預設的 Python 編輯器 IDLE 的初步使用
    + - * /, **, %
    內建的指令(built-in methods): max(), min(), sort() 等
    for 迴圈 介紹
    for i in range(1,10):
    (縮排, 空4格) 執行動作
    或是
    for i in [1,2,3,4]:
    (縮排, 空4格) 執行動作
    while 迴圈 介紹
    while 邏輯條件:
    (縮排, 空4格) 執行動作
    決策分支 介紹
    if 邏輯條件:
    (縮排, 空4格) 執行動作
    elif 邏輯條件:
    (縮排, 空4格) 執行動作
    else:
    (縮排, 空4格) 執行動作

  6. 開始 Python 烏龜繪圖,
    ref:
    A. 參考賴鵬仁老師講義: python常用Turtle指令-例子講解.doc
    B. Turtle的精采示範講義有碎形: SevenWaysToUseTurtle-PyCon2009.pdf
    C. 官網 turtle module 手冊: Turtle graphics-Python 3.8 (舊版是24.1節).pdf

    載入 turtle module,
    import turtle
    產生一個烏龜物件取名為 myTurtle
    myTurtle = turtle.Turtle()
    前進
    myTurtle.forward(100)
    左轉
    myTurtle.left(90)
    用 for 的方法 畫一個正方形
    用 for 的方法 畫一個正五邊形
    用 for 的方法 畫一個正n邊形
    Ex: 以上分別畫正方形, 正五邊形, 正 n 邊形 時, 烏龜每次需要轉多少度?

第一次上課參考資料:

  • 賴鵬仁老師講義: python常用Turtle指令-例子講解.doc

  • Turtle的精采示範講義有碎形: SevenWaysToUseTurtle-PyCon2009.pdf
    https://www.scribd.com/document/92940122/SevenWaysToUseTurtle-PyCon2009
    link

  • 官網 turtle module 手冊: Turtle graphics-Python 3.8 (舊版是24.1節).pdf, https://docs.python.org/3/library/turtle.html
    link

  • 唐瑤瑤 / 臺灣大學計算機及資訊網路中心程式設計組程式設計師, Google Colaboratory–適合Python初學者的雲端開發環境, http://www.cc.ntu.edu.tw/chinese/epaper/0052/20200320_5207.html
    link

  • 歡迎使用 Colaboratory (Python 免費線上使用)
    https://colab.research.google.com/notebooks/intro.ipynb
    link

  • 另一個可以免費線上使用Python之站 , https://repl.it/
    link

第2次上課

20200924 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

目標: 調整海龜外觀之指令, Python 自定義函數, 畫正n邊形, 用 nested for loop 嵌套迴圈, 畫多重相異正 n 邊形

  1. 複習上週介紹之海龜繪圖之指令
  2. 調整海龜外觀之指令: shape() 更改海龜形狀, turtlesize() 海龜大小, fillcolor() 海龜顏色, pensize() 畫筆之粗細, pencolor 海筆之顏色
  3. 複習畫正5邊形之角度計算, 畫正5邊形
  4. 介紹 Python 自定義函數, def functuionName(a,b,c, ,):
  5. 將畫正 5 邊形之 codes 封裝在一個函數, 呼叫此函數就會畫正5邊形
  6. 將畫正 5 邊形之 codes 推廣為畫正 n 邊形 (對指定之邊數 n), 先計算出畫正n邊形時, 海龜需轉頭之角度
  7. 將以上 6 之codes, 封裝為一個函數, 呼叫此函數就會畫正 n 邊形
  8. 使用 nested for loop 嵌套迴圈, 畫多重相異正 n 邊形
  9. 將畫多重正 n 邊形 codes 封裝在一個函數, 呼叫此函數就會畫多重相異正 n 邊形
  10. 使用 nested for loop 嵌套迴圈, 畫旋轉正 4 邊形
    Ex: 使用 nested for loop 嵌套迴圈, 畫旋轉正 n 邊形

第3次上課內容

20200930 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

目標: 畫旋轉正多邊形的各種圖案, 介紹 recursive 遞迴

  1. 複習上週介紹之, “畫多重正 n 邊形 codes 封裝在一個函數, 呼叫此函數就會畫多重相異正 n 邊形”
  2. 參考以下網站, 觀摩, 該站用 Scratch 畫旋轉正多邊形的各種圖案
    link
  3. 將畫旋轉正多邊形 codes 封裝在一個函數, 呼叫此函數, 及輸入引數: n 邊數, m 重, 就會畫正 n 邊形 m重旋轉之圖形, 挑選出你覺得最美的型態.
  4. 修改以上codes, 畫圓, 及畫旋轉圓, codes 封裝在一個函數
  5. 第2次上課介紹的是 for loop 單層迴圈, 與 nested for loop 嵌套迴圈等, 甚至可以多重迴圈, 這就是 iterated 疊代 的概念, 接下來我們介紹 recursive 遞迴, 例如 Fibonacci sequence 費氏數列,
  6. 用 for 寫一個累加的程式, 再用 recursive 的方法寫一個累加的程式
    Ex: 用 for 寫一個累乘的程式, 再用 recursive 的方法寫一個累乘的程式
    Ex: 用 for 寫一個產生Fibonacci sequence 費氏數列的程式, 再用 recursive 的方法寫一個產生Fibonacci sequence 費氏數列的程式

第4次上課內容

20201007 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

目標: 在 Google Colaboratory 上執行海龜繪圖, 費氏數列的 for 與 recursive 寫法, 觀摩 Python Turtle 模組的 demo 程式, 試著用自己的設計方法去實現簡單的2叉碎形樹,

  1. 如何在 Google Colaboratory (Python 免費線上使用) 上執行海龜繪圖
  2. Ex: 用 for 寫一個累乘的程式, 再用 recursive 的方法寫一個累乘的程式
  3. 用 for 寫一個產生Fibonacci sequence 費氏數列的程式, 再用 recursive 的方法寫一個產生Fibonacci sequence 費氏數列的程式
  4. 觀摩 Python Turtle 模組的 demo 程式的 source codes, 分析demo 中河內塔的程式碼
  5. 觀摩 Python Turtle 模組的 demo 程式的 source codes, 分析demo 中 fractal tree 的程式碼
  6. 因為demo 的源碼較不好讀, 我們試著用自己的較單純的設計方法去實現簡單的2叉碎形樹的繪製,

第5次上課內容

20201014 高中段考, 暫停一次.
20201021 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

  1. 複習 遞迴 recursive, 數列之 recursive 定義與程式語言之 recursive function 之結構之對照, 以 F(n)=2nF(n)=2^nF(n)=2n 為例
  2. 觀摩網路上碎形的圖形, 主要的特徵是: 自我相似性
  3. 再觀摩 turtle module demo 中與碎形有關的部分: forest, fractal curves, lindenmayer, tree 等
  4. 以遞迴語法畫圓內部層層嵌套一個圓
  5. 以遞迴語法畫圓內部層層嵌套兩個圓
  6. 上週, 我們試著用 用遞迴語法, 用較單純的設計方法去設計簡單的2叉碎形樹的繪製的程式結構, 今天補上codes 細節
  7. 最簡單 2 叉碎形樹, 樹枝夾角為 45 度
  8. 樹枝夾角為 可調整
  9. 樹枝夾角改為隨機擾動
  10. 左右分枝不同的收縮率

第6次上課內容

20201028 週三 13:00-16:00
地點: 高雄市新莊高中3F小電腦教室

  1. Python 物件導向介紹
  2. 觀摩與解析 Python turtle module demo 中碎形有關的 codes, 的物件導向的設計
  3. Python turtle module 的 藝術繪圖: 隨機線段藝術、板塊藝術、紫雨無聲落下

從turtle海龜動畫學習Python-高中彈性課程1相关推荐

  1. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 3 烏龜繪圖 所需之Python基礎

    "Talk is cheap. Show me the code." ― Linus Torvalds 老子第41章 上德若谷 大白若辱 大方無隅 大器晚成 大音希聲 大象無形 道 ...

  2. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10.2 藝術畫 Python 製作生成式藝術略覽

    Goal: 藉由有趣的「海龜繪圖」學會基礎的 Python 程式設計 本篇著重在以 Python 海龜繪圖模擬藝術圖形, 討論與生成式藝術的關聯. 本篇我們列舉一些網路上見到的, 用電腦程式或某些軟體 ...

  3. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 6 多重旋轉圓, 螺旋正方形

    Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計 本篇介紹基礎的 Python 海龜動畫繪圖, 確實可以只以簡單的指令畫出極為複雜有趣或美麗的圖案: 多重旋轉之圓或多邊形, 多 ...

  4. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 10.1 藝術畫 python繪製天然雪花結晶

    本篇主要是討論用 python 模擬自然界的雪花結晶形狀, (注意: 非網路上常提到的 雪花算法). "Talk is cheap. Show me the code." ― Li ...

  5. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 11.2 maze 迷宮 - 用 turtle 呈現演算法之執行動作

    Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計 本篇介紹 Python 海龜繪圖 呈現迷宮演算法等 "Talk is cheap. Show me the code ...

  6. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 9 Python 物件導向介紹

    "Talk is cheap. Show me the code." ― Linus Torvalds 老子第41章 上德若谷 大白若辱 大方無隅 大器晚成 大音希聲 大象無形 道 ...

  7. 從turtle海龜動畫 學習 Python - 高中彈性課程系列 6.1 內嵌正多邊形 類似禪繞圖

    Goal: 藉由有趣的「海龜動畫繪圖」學會基礎的 Python 程式設計 本篇介紹基礎的 Python 海龜動畫繪圖, 確實可以只以簡單的指令畫出極為複雜有趣或美麗的圖案: 內嵌正多邊形之圖案, 禪繞 ...

  8. 用免費的電腦資源協助數學的教學,學習與探索_復華中學教師營_中山大學應數系高中數學人才班_2021

    "Talk is cheap. Show me the code." ― Linus Torvalds 摘要: 直到, 在學習 R 語言的過程, 才發現有 Markdown 這種文 ...

  9. 控制項學習四(屬性與事件)

    四.初探控制項屬性(Property)的建立 1.當我們建立一個控制項(或類別),可以建立控制項的屬性(property),屬性多半是一個值,或是指到另外一個物件,或是一個集合. 請注意,在該屬性宣告 ...

最新文章

  1. LeetCode Construct Binary Tree from Preorder and Inorder Traversal(构造二叉树)
  2. Tomcat启动过程源码分析六
  3. 手机拍照功能的简单实现
  4. Array Elimination 运算,gcd,思维
  5. python3的3D开发-基于blender(1)
  6. SAP UI5 setModel of scFld Controller
  7. Jerry和您聊聊Chrome开发者工具
  8. [SpringSecurity]基本原理_两个重要的接口_UserDetailsService接口和PasswordEncoder接口
  9. 【Acwing 219. 剪纸游戏】
  10. 得推分类信息 v4.0 强大且好用的网站信息编辑管理工具
  11. 是时候了解原码、反码和补码
  12. 矩池云如何使用 conda create 创建纯净的 Python3.6 环境?
  13. 用友U8案例教程委外管理前台操作
  14. 易语言超文本浏览框支持html5,易语言 修改ie版本:使超文本浏览框或互联网浏览器变成IE9 IE10 IE11等版本...
  15. CSS中如何撑起内容为空的div
  16. jupyter python2_【精】Jupyter Notebook同时支持Python2和Python环境
  17. 为什么换了固态硬盘电脑会快?详解硬盘与内存的关系
  18. python量化交易pandas中的用途
  19. 主机字节序(小端:X86,STM32;大端:51单片机,STM8)
  20. DOS批处理中的FORFILES用法

热门文章

  1. 计算机,软件工程类毕业论文选题要求
  2. 51单片机和315M无线发射模块编码与解码
  3. 「Python|音视频处理|场景案例」如何使用ffmpeg下载m3u8视频到本地并保存成mp4
  4. 2021年度训练联盟热身训练赛第五场 F,G,H,I
  5. 【项目管理一点通】(44) 用户测试(Alpha测试)
  6. 少年,这里有5本Python3爬虫书
  7. spacedesk-把ipad变成显示器-真香经验全面分享
  8. (8)香橙派+apache2与php+天猫精灵=自建平台语音支持--天猫精灵对接3
  9. sqlserver拼接字符串换行_sqlserver的换行
  10. Pathon 编写程序在屏幕中心绘制正方形