事務屋さんの備忘録

主にプログラミングのことを書いていきます。メモというか備忘録的な感じで。プログラミングといっても、私はプロのエンジニアでも本職のプログラマーでもありません。単なる事務職をやってるサラリーマンで、空いた時間にちょこちょこっとプログラミングしてる程度です。よってこのブログに記載したことが誤っていたり、もっとよい方法がある場合もあると思います。その場合には、ご指摘いただけると嬉しいです。また、このブログを読んで役に立った、なんて方がいらっしゃったら幸いですね。

Python

Python 基礎 グラフ

メモ。グラフいろいろ。 #グラフ import matplotlib.pyplot as plt #matplotlib.pyplotモジュールの読み込み data=[2, 2.3, 4.1, 2.4, 5.3, 3.2, 4.6] #グラフ化するデータ plt.plot(data) #グラフを書く plt.show() #グラフを表示する # x軸の要素はインデ…

Python 基礎 テキストファイル操作

メモ。テキストファイル操作いろいろ。 #テキストデータを読み込む file="./test/fox.txt" # "test/fox.txt" でも可 fileobj=open(file) text=fileobj.read() fileobj.close() print(text) print("-----------") #with-asを使ってファイル処理 close()が不要…

Python 基礎 クラス

メモ。クラスいろいろ。 class Car: #クラス変数 maker="PEACE" #自動車メーカー count=0 #台数 #初期化メソッド def __init__(self,color="white"): self.color=color #引数で受け取った値を代入 self.mileage=0 #0からスタート #インスタンスメソッド def …

Python 基礎その7 関数

メモ。関数いろいろ。 #引数が無く、戻り値がある関数 def hello(): return "Hello!!!" #関数の実行 msg=hello() print(msg) #Hello!!! #Test1 from random import randint def dice(): num=randint(1,6) #1~6の乱数を発生させる return num #dice()を5回呼…

Python 基礎その6 辞書 dict

メモ。辞書 dict いろいろ。 #dict 辞書 stock={"S":7,"M":12,"L":3} print(stock) #{'S': 7, 'M': 12, 'L': 3} metro={ "G":"銀座線", #コメント "M":"丸の内線", #コメント "H":"日比谷線" #コメント } print(metro) #{'G': '銀座線', 'M': '丸の内線', 'H…

Python 基礎その5 リスト

メモ。リストいろいろ。 #Test1 numbers=[4,8,15,16,23,42] colors=["red","green","blue"] print(numbers) print(colors) print("-" *5) #Test2 a=10 b=20 c=30 abc=[a,b,c] print(abc) print("-" *5) #Test3 a=10 b=20 c=30 abc=[a,b,c] b=99 #bの値を変更…

Python 基礎その4 繰り返し処理

メモ。 #繰り返し count=1 while count<=5: print(count) count += 1 print("-" *5) #break from random import randint while True: a=randint(1,13) b=randint(1,13) c=randint(1,13) if a+b+c == 21: break print(a,b,c) print("-" *5) #continue numbers…

Python 基礎その3 分岐処理

メモ。 #条件分岐 #if文 v=-1 if v<0: v=0 v=v*2 print(v) #0 v=3 if v<0: v=0 v=v*2 print(v) #6 #if else文 sum=50+37+10 limit=100 if sum>limit: result="合格" else: result="不合格" result+=" / "+str(sum-limit) print(sum) #合格点 print("-" * 20)…

Python 基礎その2

メモ。 #文字列操作 s="Apple iPhoneとGoogle Android" print(s.upper()) #大文字変換 print(s.lower()) #小文字変換 print(s.swapcase()) #大文字小文字の入替 s1="may the force be with you!" print(s1.capitalize()) #文字列の1文字目だけを大文字に pri…

Python 基礎その1

a=10 b=20 c=30 ans=a+b+c print(a,b,c, sep="、",end="/以上") print(ans) r=round(23.5) print(r) msg="こんにちは" where="箱根" language="Python3" print(msg,where,language) color="選んだ色は\n緑\n黄色" print(color) msg2="それは\"python3\"です"…