はじまる

適当な事を適当に書く

Python の REPL(対話モード) で for 文などの構文を書く

Mac です。

% uname -a
Darwin hoge 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 arm64

こうなったときどうしたらいいかわからなかった。

% python3
Python 3.8.9 (default, Jul 19 2021, 09:37:30) 
[Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1,2,3]
>>> for i in a:
...   print(i)
... 

対応は2通り。

  • Shift + Enter を入力する
  • Enter を2回入力する。
% python3
Python 3.8.9 (default, Jul 19 2021, 09:37:30) 
[Clang 13.0.0 (clang-1300.0.27.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1,2,3]
>>> for i in a:
...   print(i)
... 
1
2
3

以上。