0
1

概要

MacのローカルにてPythonのスクリプトファイルを実行してみる。

前提

  • 下記の方法でPythonの3.10.0がMacに入っており、実行できること

  • 実行するPythonのコードは下記で、test.pyというファイルで任意のディレクトリに設置されているものとする(10回ループを繰り返し、インデックスが奇数か偶数かを出力するコード)

    test.py
    def loop_and_print():
        for i in range(10):
            if i % 2 == 0:
                print(f"{i}は偶数です")
            else:
                print(f"{i}は奇数です")
        print("ループが完了しました")
    
    loop_and_print()
    

方法

  1. 「前提」で上げたtest.pyのカレントディレクトリにターミナルで移動

  2. ターミナルで下記を実行してtest.pyを実行

    python test.py
    
  3. 下記の様に出力されたら完了

    $ python test.py
    0は偶数です
    1は奇数です
    2は偶数です
    3は奇数です
    4は偶数です
    5は奇数です
    6は偶数です
    7は奇数です
    8は偶数です
    9は奇数です
    ループが完了しました
    
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1