「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
>python
>python Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ^Z >
>python --version Python 3.9.5
pip3 install XXXX
>python -m pip install --upgrade pip
python --version
python
>>>1+1 2
>>>type(10) <class 'int'>
>>>x=10 >>>print(x) 10
>>>a=[1,2,3,4,5] >>>print(a) [1,2,3,4,5] >>>a[0] 1 >>>a[4] 5 >>>a[4]=99 >>>a[4] 99 >>>print(a) [1,2,3,4,99]
>>>dic={'hoge1':1} >>>dic['hoge2']=2 >>>print(dic) {'hoge1': 1, 'hoge2': 2}
>>>hungry = True >>>sleepy = False >>>type(hungry) <class 'bool'> >>>not hungry False >>>hungry and sleepy False >>>hungry or sleepy True
>>>hungry = True >>>if hungry: ... print("im hungry") # 半角スペースのインデントが必要 ... im hungry >>>hungry = False >>>if hungry: ... print("im hungry") # 半角スペースのインデントが必要 ...else: ... print("im not hungry") # 半角スペースのインデントが必要 ... print("im sleepy") ... im not hungry im sleepy
>>>for i in [1,2,3]: ... print(i) # 半角スペースのインデントが必要 ... 1 2 3
>>>def hello(): ... print("hello!") ... >>>hello() hello! >>>def hello(object): ... print("hello " + object + "!") ... >>>hello("hoge") hoge hello!
対話モードを終了するには、 exit() を実行する。
テキストファイルに
print("im hungry")
と書いて、拡張子を*.pyとして保存する(例 hungry.py)。
cdでカレントディレクトリに移動して、
>python hungry.py im hungry
2 ** 3
10 % 3 1
10 // 3 3
1.0e7
1.0e-7
"hoge" + "hoge" => "hogehoge"
"hoge" * 2 => "hogehoge"
int("2022") => 数値の2022
month = 9 day = 1 temp = 30 '{}月{}日の気温は{}度です。'.format(month, day, temp)
# コメント
""" コメント """
配列の事。
hoge = ['aaa', 'bbb', 'ccc', 'ddd']
hoge[0] => 'aaa'
hoge[-3] => 'bbb'
hoge[1:3] => ['bbb', 'ccc']
== != > < >= < =
and or not
コレクション型のデータに特定の要素が含まれているかどうか
if(SelectとかSwitchは無い)
if 条件式A: ... elif 条件式B: ... else: ...
条件式Aが真(true)の場合に実行する処理
条件式Aが偽(false)で条件式Bが真(true)の場合に実行
すべての条件式が偽(false)の場合に実行
foreach的なforのみ実装
for 変数 in オブジェクト: 実行する処理
for num in range(5, 10): print(num) 5 6 7 8 9
for num in range(0, 10, 3): print(num) 0 3 6 9
for index, value in enumerate(hoge): ...
for value1, value2 in zip(hoge1, hoge2): ...
def 関数名(仮引数, ...): ... return 値
関数名(実引数, ...)
def hello_world(): print("Hello") print("world")
hello_world()
def 関数名(仮引数1=デフォルト値, 仮引数2=デフォルト値): ... return
関数名(仮引数名1=実引数1, 仮引数名2=実引数2)
def 関数名(*Tuple):
関数名(1, 2, 3, 4, 5, 6, 7, 8)
def 関数名(**Dictionary):
def 関数名(key1=1, key2=2, key3=3):
class クラス名: def __init__(self, 引数, ...): #コンストラクタ ... def メソッド名1(self, 引数, ...): #メソッド1 ... def メソッド名2(self, 引数, ...): #メソッド2 ...
class Man: def __init__(self, name): self.name=name print("inited!") def hello(self): print("hello " + self.name + "!") def goodbye(self): print("good-bye " + self.name + "!")
m = Man("hoge") m.hello() m.goodbye()