【授業事例】パソコン教室 スマホ・タブレット教室 プログラミング教室 キュリオステーション鶴見校

  • パイソン プログラミング教室
    イテレータ(StopIteration例外)

itr = iter([0, 1, 2])
print(next(itr))
print(next(itr))
print(next(itr))
print(next(itr))

0
1
2
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-26-734cb73b5ced> in <module>
      3 print(next(itr))
      4 print(next(itr))
----> 5 print(next(itr))

StopIteration: 
  • パイソン プログラミング教室
    クラス 継承、クラス変数の上書き、クラス変数追加、メソッドの上書き、super()、メソッドの追加
class Onigiri:
    cat = "おにぎり"
    tane = "たね"
    base = "しゃり"
    
    def show_attrs(self):
        print("tane: {}, tane: {}, cat: {}".format(self.tane, self.base, self.cat))

n = Onigiri()
n.show_attrs()

class Ume(Onigiri):
    tane = "うめ"
    price = 200    
    def show_attrs(self):
        super().show_attrs()
        print("price: {}円".format(self.price))
    def show_price(self, num = 2):
        result = self.price * num
        print("{}個の値段(一皿){}円".format(num, result))
    
m = Ume()
m.show_attrs()
m.show_price()
  • パイソン プログラミング教室
    TypeError

def func(a,b):
    print(a+b)
    
func(1)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-153e6692723b> in <module>
      2     print(a+b)
      3 
----> 4 func(1)

TypeError: func() missing 1 required positional argument: 'b'
  • VBA Excel Application.Quit
  • WiMAXポケット WIFI接続(パソコン、スマホ)
  • パイソン プログラミング教室
    円周率

import math
pi = math.pi
print(pi)

3.141592653589793
  • パイソン プログラミング教室
    マングリング

class test:
    def __init__(self):
        self.a = 1
        self._b = 1
        self.__c = 1
        self.__d_ = 1
        self.__e__ = 1
        
t = test()
print(dir(t))
t.a
t._b
t.__c
t.__d_
t.__e__
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__e__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_b', '_test__c', '_test__d_', 'a']
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-aee7c96b3d2c> in <module>
     11 t.a
     12 t._b
---> 13 t.__c
     14 t.__d_
     15 t.__e__

AttributeError: 'test' object has no attribute '__c'
  • パイソン プログラミング教室
    クラス クラス変数
class MyC:
    text = "class text"
    
print(MyC.text)

MyC.text = "new text"
MyC.text
  • パイソン プログラミング教室
    クラス インスタンス変数
class MyC:
    def __init__(self, text="abcd"):
        self.text = text
        
a = MyC()
b = MyC(text="eee")
c = MyC(text="hhh")

print(a.text)
print(b.text)
print(c.text)

a.text = "123"

print(a.text)
  • ワード 情報 文書の保護 パスワードを使用して暗号化
  • GigaFile便の使い方
  • パイソン プログラミング教室
    クラスの基本(データ属性、メソッド)
class Car:
    w = 5000
    num = 4
    
    def calc_w_p_w(self):
        return self.w / self.num

mycar = Car()
mycar.calc_w_p_w()
  • パイソン プログラミング教室
    GUIアプリ開発
from tkinter import *
from tkinter import messagebox, ttk
import subprocess

def clicked1():
    messagebox.showinfo(root.title(), 'Clicked! 1')

def clicked2():
    subprocess.Popen(r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')

def clicked3():
    subprocess.Popen(r'C:\Users\yu2ka\Desktop\MonitorOff.exe')

root = Tk()
root.title('TextEditor')
root.geometry('500x200')

button1 = ttk.Button(text='Press here!', command=clicked1)
button1.pack()
button2 = ttk.Button(text='Press here!', command=clicked2)
button2.pack()
button3 = ttk.Button(text='Press here!', command=clicked3)
button3.pack()

root.mainloop()
  • Welbyマイカルテの使い方
  • トレンドマイクロ ウイルスバスター クラウドのインストール
  • パイソン ord (short for ordinal 序数)
  • パイソン プログラミング教室
    リスト、タプル、文字列 比較
>>> [0, 1, 2] == [0, 1, 2]
True
>>> (0, 1, 2) == (0, 1, 2)
True
>>> 'abc' == 'abc'
True
>>> 'abc' < 'abd'
True
>>> 'abc' < 'ab'
False
>>>
  • パイソン プログラミング教室
    辞書キー ループ、インデックス ループ
    zip ループ

>>> for key, val in idict.items():
...     print(key, val)
...
1 one
2 two
3 three
>>> mnt = ['f', 'k', 'j']
>>> for i, m in enumerate(mnt):
...     print(i, m)
...
0 f
1 k
2 j
>>> o = [1, 2, 3]
>>> m = ['f', 'k', 'j']
>>> height = [3776, 3193, 3011]
>>> for order, mt, ht in zip(o, m, height):
...     print(order, mt, ht)
...
1 f 3776
2 k 3193
3 j 3011
  • avast antivirus アンインストール
  • Visual Code Studio, Insert Date String Extensionのインストール
  • パイソン プログラミング教室 タプルをキー 辞書の生成(内包表記)

prefs = ['hok', 'hok', 'tok', 'kan']
cities = ['sap', 'hak', 'min', 'yok']
pops = [100, 200, 300, 400]
dict = {(state,city): population for state, city, population in zip(prefs, cities, pops)}
dict

{('hok', 'sap'): 100,
 ('hok', 'hak'): 200,
 ('tok', 'min'): 300,
 ('kan', 'yok'): 400}
  • パイソン プログラミング教室 辞書の生成(内包表記)
sd = {x: x*x for x in range(21)}
sd
{0: 0,
 1: 1,
 2: 4,
 3: 9,
 4: 16,
 5: 25,
 6: 36,
 7: 49,
 8: 64,
 9: 81,
 10: 100,
 11: 121,
 12: 144,
 13: 169,
 14: 196,
 15: 225,
 16: 256,
 17: 289,
 18: 324,
 19: 361,
 20: 400}
xyd = {(x, y): x*y for x in range(3) for y in range(3)}
xyd
{(0, 0): 0,
 (0, 1): 0,
 (0, 2): 0,
 (1, 0): 0,
 (1, 1): 1,
 (1, 2): 2,
 (2, 0): 0,
 (2, 1): 2,
 (2, 2): 4}
  • Excel VBA Worksheets(“Sheet1”).PageSetup.Orientation = xlLandscape の使い方
  • パイソン プログラミング教室 Jupyterの使い方
  • パイソン プログラミング教室
    辞書 内包表記による生成
>>> sd = {x: x*x for x in range(12)}
>>> sd
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121}
  • パイソン プログラミング教室
    辞書(dict)
>>> pj = {1: 'hok', 2: 'aom', 3: 'iwa'}
>>> pj
{1: 'hok', 2: 'aom', 3: 'iwa'}
>>> pj[1]
'hok'
>>> pj.get(0)
>>> pj.get(1)
'hok'
  • パイソン プログラミング教室
    辞書(dict)for 要素の取出し
>>> pj = {1: 'hok', 2: 'aom', 3: 'iwa'}
>>> for x in pj:
...     print(x)
...
1
2
3
>>> for x in pj.keys():
...     print(x)
...
1
2
3
>>> for x in pj.values():
...     print(x)
...
hok
aom
iwa
>>>
  • パイソン プログラミング教室
    集合 比較
>>> a = set('abcdef')
>>> b = set('abcdef')
>>> c = set('abc')
>>> a == b
True
>>> a == c
False
>>>
>>> c <= a
True
>>> c.issubset(a)
True
>>> a >= c
True
>>> a.issuperset(c)
True
>>>
  • パイソン プログラミング教室
    集合 演算
>>> a = set('abcdef')
>>> b = set('efghi')
>>> a - b
{'b', 'd', 'c', 'a'}
>>> a | b
{'e', 'f', 'd', 'c', 'b', 'g', 'i', 'h', 'a'}
>>> a & b
{'e', 'f'}
>>> a ^ b
{'b', 'g', 'c', 'i', 'd', 'h', 'a'}
>>>
  • パイソン プログラミング教室
    集合の生成(内包表記)
>>> p = {2, 3, 5, 7, 11, 13}
>>> ps = {x**2 for x in p}
>>> ps
{4, 9, 169, 49, 121, 25}
>>>
  • パイソン プログラミング教室
    タプルのアンパック
>>> ts2 = 1, 4, 9, 16, 25
>>> ts2
(1, 4, 9, 16, 25)
>>> a, b, c, d, e = ts2
>>> a
1
>>> b
4
>>> c
9
>>> d
16
>>> e
25
  • パイソン プログラミング教室
    set (集合) 要素の追加(add)
>>> big = {'sap', 'sen', 'tok', 'nag', 'osa', 'fuk', 'osa'}
>>> big
{'sen', 'sap', 'nag', 'osa', 'tok', 'fuk'}
>>> seta = set('abcdefgh')
>>> seta
{'f', 'c', 'b', 'a', 'e', 'g', 'h', 'd'}
>>> seta.add('i')
>>> seta
{'f', 'c', 'b', 'a', 'i', 'e', 'g', 'h', 'd'}
>>>
  • パイソン プログラミング教室
    set (集合) 要素の削除(remove, discard, pop. clear)
>>> big = {'sap', 'sen', 'tok', 'nag', 'osa', 'fuk', 'osa'}
>>> big
{'sen', 'sap', 'nag', 'osa', 'tok', 'fuk'}
>>> seta = set('abcdefgh')
>>> seta
>>> seta.remove('g')
>>> seta
{'f', 'c', 'b', 'a', 'i', 'e', 'h', 'd'}
>>> seta.remove('z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'z'
>>>
>>> seta
{'f', 'c', 'b', 'a', 'i', 'e', 'h', 'd'}
>>> seta.remove(x) if x in seta else print(x, 'is not found')
z is not found
>>> x = 'f'
>>> seta.remove(x) if x in seta else print(x, 'is not found')
>>>>>> seta.pop()
'c'
>>> seta.pop()
'b'
>>> seta
{'a', 'i', 'e', 'h', 'd'}
>>>
日本IBM出身
ホームページビルダー元開発責任者
鎌田裕二
責任指導
横浜市鶴見区のパソコン教室⇒

お問い合わせ TEL:045-567-8393
【開校15年 総受講生 1,800名以上】
小学生から90才まで通学実績有