「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
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
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()