投稿

6月, 2020の投稿を表示しています

「Python」試用録(15)」

%F0: 「Python」試用録(15)」/*「 作業中 」*/ 「OctalPython」作成のための断片的備忘録です. /*背景色は(茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「緑」は定義行のみ(他ではシアン).「茶」の語句があるパラグラフは「IDも茶」*/ %F11: 資料の参照/*「□で場所を明示」*/ `▼ --------------------------------------------------------------------------------  ①[Lang_□]@ https://docs.python.org/ja/3/reference/index.html  ②[Lib_□]@ https://docs.python.org/ja/3/library/index.html#library-index  ③[Tutr_□]@ https://docs.python.org/ja/3/tutorial/ ⑥[W6_□]@ https://drive.google.com/file/d/1191Ev62Uo9yha0w87Kl5A01DsVCP7e-x/view?usp=sharing  ⑦[Trial_□]@h ttps://oshino3.blogspot.com/2020/05/python.html -------------------------------------------------------------------------------- `▲ %F2: [Trial_□]のパラグラフに関するメモ `▼ -------------------------------------------------------------------------------- (0) 暫定版です (1)参考資料  ① 【 [%26](6).[Trial_2] 】 @ https://oshino3.blogspot.com/2020/05/python_21.html  ② 【 [%71(2)①].[Trial_7] 】 @ https://oshino3.blogspot.com/2020/06/python7.html  

「Python」試用録(14)」

%E0: 「Python」試用録(14)」/*「Extracted Paragraphs」*/ 「OctalPython」作成のための断片的備忘録です. /*背景色は(茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「緑」は定義行のみ(他ではシアン).「茶」の語句があるパラグラフは「IDも茶」*/ %E11: 資料の参照/*「□で場所を明示」*/ `▼ --------------------------------------------------------------------------------  ①[Lang_□]@ https://docs.python.org/ja/3/reference/index.html  ②[Lib_□]@ https://docs.python.org/ja/3/library/index.html#library-index  ③[Tutr_□]@ https://docs.python.org/ja/3/tutorial/  ④ [Lib_]https://docs.python.org/ja/3/library/random.html  ・数値と数学モジュール random//*「index.html#library-index」*/  ⑤ [Lang_8.5]@ https://docs.python.org/ja/3/reference/compound_stmts.html ・with文とコンテキストマネージャ セクションを参照してください  ⑥ https://ja.wikipedia.org/wiki/ASCII ⑦[W6_□]@ https://drive.google.com/file/d/1191Ev62Uo9yha0w87Kl5A01DsVCP7e-x/view?usp=sharing -------------------------------------------------------------------------------- `▲例:/*【[Tutr_4.8]全文】*/ %E2: [Trial_□]のパラグラフに関するメモ `▼ ---------------------------

「Python試用録(13)」

% D0: 「Python試用録(13)」 「WILDの処理系」作成のための「 断片的備忘録 ★」です. /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「 緑 」は定義行のみ(他では シアン ).「 茶 」の語句があるパラグラフは「 IDも茶 」*/ %D1: [@IT_37]/*「例外の送出と例外クラス」*/ `▼ -------------------------------------------------------------------------------- (0)「In[4]:」 class MyStack:   def __init__(self):       self.stack = []   def push(self, item):       self.stack.append(item)   def pop(self):     if len(self.stack) == 0:       raise IndexError('stack is empty')     return self.stack.pop() (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1909/10/news013.html  ② https://docs.python.org/ja/3/reference/simple_stmts.html#the-raise-statement (2)「②」の説明 -------------------------------------------------------------------------------- `▲ %D2:「Python試用録(□)」引用記事一覧 `▼ -------------------------------------------------------------------------------- (1)[@IT_□]/*「目次」*/ (2)[@IT_2]/*「Hello Python(2/3)」*/ (3)[@IT_3]/*「数値と算術演算(1/2)」*/ (4)[@IT_5]

「Python試用録(12)」

%C0: 「Python試用録(12)」 「WILDの処理系」作成のための「 断片的備忘録 」です.  ★https://oshino3.blogspot.com/ /*背景色は(茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「緑」は定義行のみ(他ではシアン).「茶」の語句があるパラグラフは「IDも茶」*/ %C1: [@IT_30]/*「スタックとキュー」*/ `▼ -------------------------------------------------------------------------------- (0)「In[4]:」   class MyStack:     def_init_(self):       self.stack = []     defpush(self, item):       self.stack.append(item)     def pop(self):       result = self.stack[-1]       del self.stack[-1]       return result   「In[5]:」     mystack = MyStack()     mystack.push(0)     mystack.push(1)     print(mystack.pop())     print(mystack.pop()) (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1908/06/news015.html  ② https://www.isc.meiji.ac.jp/~mizutani/python/stack.html  ③ https://qiita.com/woolon/items/9efc596cffc5970c187b  ④ https://docs.python.org/ja/3/tutorial/datastructures.html#using-lists-as-stacks (2)「In[5]:」の実行結果は「1」,「0」. (3) (4) -----------------------------

「Python試用録(11)」

%B0: 「Python試用録(11)」 「WILDの処理系」作成のための「 断片的備忘録 」です. /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「 緑 」は定義行のみ(他では シアン ).「茶」の語句があるパラグラフは「 IDも茶 」*/ %B1: [@IT_28]/*「クラス」*/ `▼ -------------------------------------------------------------------------------- (0)「In[2]:」    class Point:      pass   「In[3]:」    point1=point()    print(type(point1))  ①pass文を使い、何もしないクラスを定義。 (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1907/26/news020.html  ② https://docs.python.org/ja/3/reference/compound_stmts.html#class-definitions   ・メタクラス/*[Py_3.3.3.1]*/     デフォルトでは、クラスは type() を使って構築されます。     クラス本体は新しい名前空間で実行され、     クラス名が type(name, bases, namespace) の結果にローカルに束縛される。 (2)「Out[3]:」   <class '_main_.Point'>  ①対話環境(__main__環境)上で定義されたクラス(Point)であることを意味。 (3) -------------------------------------------------------------------------------- `▲

「Python試用録(10)」

%A0: 「Python試用録(10)」 「WILDの処理系」作成のための「 断片的備忘録 」です. /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「 緑 」は定義行のみ(他では シアン ).「茶」の語句があるパラグラフは「 IDも茶 」*/ %A1: [@IT_27]/*「演算子のまとめ」*/ `▼ -------------------------------------------------------------------------------- (0)「In[1]:」   y = 'py' * 2  # 右辺の式「'py' * 2」を計算した結果である「'pypy'」が代入される   a, b = 2, 3   # 複数のターゲットへの代入   c, d, e, *f = [3, 4, 5]  # 変数fの値はどうなる? (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1907/23/news010.html  ② https://docs.python.org/ja/3/reference/expressions.html   ・この章と以降の章での拡張BNF (extended BNF) 表記は、字句解析規則ではなく、   構文規則を記述するために用いられています。   6.5. べき乗演算      左側にある単項演算子よりも強い結合優先順位となります。      一方、右側にある単項演算子よりは弱い結合優先順位になっています。   6.7. 二項算術演算     @ (at) 演算子は行列の乗算に対し使用されます。     / (除算: division) および // (切り捨て除算: floor division) は、       引数同士の商を与えます。     % (剰余: modulo) 演算は、第一引数を第二引数で除算したときの剰余になる   6.15. 式のリスト   6.16. 評価順序   6.17. 演算子の優先順位   7.2. 代入文   7.2.1. 累算代入文     累算代入文は、二項演

「Python試用録(9)」

%9: 「Python試用録(9)」 「WILDの処理系」作成のための断片的備忘録です. /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ %91: [@IT_26]/*「オブジェクトの同一性」*/ `▼ -------------------------------------------------------------------------------- (0)「In[2]:」    mylist = [1, 2, 3]    yourlist = mylist    otherlist = list([1, 2, 3])    print('mylist == yourlist?', mylist == yourlist)    print('mylist == otherlist?', mylist == otherlist) (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1907/16/news023.html  ② https://docs.python.org/ja/3/reference/compound_stmts.html#class-definitions   ・クラス定義は実行可能な文です。継承リストは通常、基底クラスリストを与えます     classdef    ::=  [decorators] "class" classname [inheritance] ":" suite     inheritance ::=  "(" [argument_list] ")"     classname   ::=  identifier (2)「Out[2]:」    mylist == yourlist? True    mylist == otherlist? False (3)「(2)」よりも【[%81](1)②】の     --------------------------------     >>> x = [1, 2, 3]     &

「Python試用録(8)」

%8: 「Python試用録(8)」 「WILDの処理系」作成のための「断片的備忘録★」です.  ★ https://oshino3.blogspot.com/ /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「 緑 」は定義行のみ(他では シアン ).「 茶 」の語句があるパラグラフは「 IDも茶 」*/ %81: [@IT_19]/*「タプル」*/`▼ -------------------------------------------------------------------------------- (0)「In[20]:」    sk = ('shinji', 'kawasaki', 80)    mi = ('masahiko', 'isshiki', 65)    person_list = [mi, sk]    for person in person_list:      print('{person[1]}さんの体重は{person[2]}kgです') (1)参考資料  ① https://www.atmarkit.co.jp/ait/articles/1906/14/news015_3.html  ② https://docs.python.org/ja/3/library/functions.html#func-tuple  ------------------------------------------------------  ・タプル型 (tuple) と シーケンス型 --- list, tuple, range   にドキュメント化されています。  ①class tuple([iterable])  ・tuple は、実際は関数ではなくイミュータブルなシーケンス型で、  ②zip(*iterables)   それぞれのイテラブルから要素を集めたイテレータを作ります。   ・zip() に続けて * 演算子を使うと、zip したリストを元に戻せます:     >>> x = [1, 2, 3]     >

「Python試用録(7)」

%7: 「Python試用録(7)」 「WILDの処理系」作成のための「断片的備忘録★」です.  ★ https://oshino3.blogspot.com/ /*背景色は( 茶: 編集・確認中; 灰色: 確認済; 緑: 非慣用記法; 白色: 初期化済)*/ /*「 緑 」は定義行のみ(他では シアン ).「茶」の語句があるパラグラフは「 IDも茶 」*/ %71: [@IT_16]/*「リストの基本」*/ `▼ -------------------------------------------------------------------------------- (0)「In[6]:」   somelist = ['python', 1, 100.5]   print(somelist) (1)参考資料:① https://docs.python.org/ja/3/library/functions.html#func-list (2) class list([iterable])  list は、実際には関数ではなくミュータブルなシーケンス型で、  リスト型 (list) と シーケンス型 --- list, tuple, range にドキュメント化されています。   ①class list([iterable])   リストの構成にはいくつかの方法があります:   ・角括弧の対を使い、空のリストを表す: []   ・角括弧を使い、項目をカンマで区切る: [a]、[a, b, c]   ・リスト内包表記を使う: [x for x in iterable]  ②class tuple([iterable])  タプルの構成にはいくつかの方法があります:   ・丸括弧の対を使い、空のタプルを表す: ()   ・カンマを使い、単要素のタプルを表す: a, または (a,)   ・項目をカンマで区切る: a, b, c または (a, b, c)   ・組み込みの tuple() を使う: tuple() または tuple(iterable)  ③class range(start, stop[, step])   ・step が正の場合、range r の内容は式