slow-starter

なにをやるにもslow start……。

python_005

これまでオンラインの実行環境でpythonを勉強してた。

でも、ちゃんとローカルでも環境を作ってみたいので環境構築した。

ローカル実行環境構築

python インストール

Pythonの公式サイトから、インストールパッケージをダウンロード。

最新版のWindows用のpython3をダウンロードする。(現在の最新は3.7.0)
念のため、python2もダウンロードしておく。(現在の最新は2.7.15)

ダウンロードしたパッケージをインストール。
あまり気にしてなかったが、デフォルトでは以下のpathにインストールされるらしい。

C:\Users\<<UserName>>\AppData\Local\Programs\Python\Python37

そのままではPathが通ってないので、Pathを設定する。 設定後、コマンドプロンプト(cmd)からPythonが実行可能になる。

vscode インストール

実行環境は「Visual Studio Code(vscode)」が良いらしいので、こちらも公式サイトからダウンロード。

こちらもダウンロードしたパッケージをインストール。

vscode 日本語化

vscodeが日本語表示されないので、以下を参照しつつ日本語化。

1. 「Ctrl+Shift+P」押下。
2. 「>」のプロンプトに 「Configure Display Language」と入力し、サジェストされたメニューを選択し、実行。
3. 「locale.json」というファイルが開くので、"locale":"en"を"locale":"ja"と修正し、vscodeを再起動。

でも、vscodeを再起動したけど、英語のまま…。

ということで以下を参照し、拡張機能「Japanese Language Pack for Visual Studio」をインストール。

1. 「Ctrl+Shift+X」押下。
2. 「>」のプロンプトに 「Japanese Language」と入力し、サジェストされたメニューを選択し、インストール。

vscodeを再起動し、日本語化完了!

続きは後日…。

python_004

入門程度のpythonをやってみて、気になったpython2とpython3の違い。

int を intで割り算した結果が違う

python2

a = 1/2
print(a)
# 0
print(type(a))
# <type 'int'>

a = 1//2
print(a)
# 0
print(type(a))
# <type 'int'>

python3

a = 1/2
print(a)
# 0.5
print(type(a))
# <class 'float'>

a = 1//2
print(a)
# 0
print(type(a))
# <class 'int'>

printの書式が異なる

python2(1)

print("test")
# 「end=''」など未実装のキーワード引数ををつけるとSyntax Error...
# test
print "test"
# test

python3(1)

print("test")
# test
print "test"
# SyntaxError...

range関数の返す値が異なる

python2(2)

a = range(3)
print(a)
# [0, 1, 2]
print(type(a))
# <type 'list'>

python3(2)

a = range(3)
print(a)
# range(0, 3)
print(type(a))
# <class 'range'>

数学1A_003

pythonを使いつつ、数学1Aの基礎を復習

# coding: utf-8
import numpy as np

t = float('inf')

print('deg      rad      sin      cos       tan    ')
print('-------  -------  -------  --------  -------')

fmt = '  '.join(['%7.2f'] * 5)
for deg in range(0, 361, 30):
    rad = np.radians(deg)
    if deg in (90, 270):
        t = float('inf')
    else:
        t = np.tan(rad)
    print(fmt % (deg, rad, np.sin(rad), np.cos(rad), t))
# deg      rad      sin      cos       tan    
# -------  -------  -------  --------  -------
#    0.00     0.00     0.00     1.00     0.00
#   30.00     0.52     0.50     0.87     0.58
#   60.00     1.05     0.87     0.50     1.73
#   90.00     1.57     1.00     0.00      inf
#  120.00     2.09     0.87    -0.50    -1.73
#  150.00     2.62     0.50    -0.87    -0.58
#  180.00     3.14     0.00    -1.00    -0.00
#  210.00     3.67    -0.50    -0.87     0.58
#  240.00     4.19    -0.87    -0.50     1.73
#  270.00     4.71    -1.00    -0.00      inf
#  300.00     5.24    -0.87     0.50    -1.73
#  330.00     5.76    -0.50     0.87    -0.58
#  360.00     6.28    -0.00     1.00    -0.00