Pyothonインタプリタ
Pythonインタプリタは対話的に処理を行わせることができる仕組みです。
Perlのone-linerみたいなことをホイホイと実行できる。
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable. Visit http://www.python.org/download/mac/tcltk/ for current information. >>> version Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> version NameError: name 'version' is not defined >>> --version Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> --version NameError: name 'version' is not defined >>> python Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> python NameError: name 'python' is not defined >>> ls Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> ls NameError: name 'ls' is not defined >>> 1 + 2 3 >>> 1-2 -1 >>> 4*5 20 >>> 7/5 1.4 >>> 3 ** 2 9 >>> 3 ** 50 717897987691852588770249 >>> 3 ** 1000 1322070819480806636890455259752144365965422032752148167664920368226828597346704899540778313850608061963909777696872582355950954582100618911865342725257953674027620225198320803878014774228964841274390400117588618041128947815623094438061566173054086674490506178125480344405547054397038895817465368254916136220830268563778582290228416398307887896918556404084898937609373242171846359938695516765018940588109060426089671438864102814350385648747165832010614366132173102768902855220001 >>> type(10) <class 'int'> >>> type(2.718) <class 'float'> >>> type("miki is beautiful") <class 'str'> >>> x = 10 >>> print(x) 10 >>> x = 100 SyntaxError: unexpected indent >>> x=100 >>> print(x) 100 >>> y = 3.14 >>> x * y 314.0 >>> type(x * y) <class 'float'> >>> a = [1,2,3,4,5,6] # list >>> print(a) [1, 2, 3, 4, 5, 6] >>> print(a) [1, 2, 3, 4, 5, 6] >>> print(a) #一個前の>>>カーソルをクリックしてエンターキーを押すとコピーされる [1, 2, 3, 4, 5, 6] >>> print(a) #十字キーでも移動してエンターキーを押すとコピーされる [1, 2, 3, 4, 5, 6] >>> len(a) 6 >>> a[0] #first element access 1 >>> a[4] #4th element access 5 >>> a[4] #change 4th element value. 5 >>> a[4]=100 #change 4th element value. >>> print(a) #changed value check [1, 2, 3, 4, 100, 6] >>> a[4] 100 >>> a[0:2] [1, 2] >>> a[0:100] [1, 2, 3, 4, 100, 6] >>> a[1:] [2, 3, 4, 100, 6] >>> a[:3] [1, 2, 3] >>> a[:100] [1, 2, 3, 4, 100, 6] >>> a[:-1] [1, 2, 3, 4, 100] >>> a[:-100] [] >>> a[:-2] [1, 2, 3, 4]
結構楽しい。