0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python実行環境構築

Last updated at Posted at 2025-10-12

【Python実行環境構築】

Windows11で実施。
Python 3.7以降が必要。

  1. Python公式サイトからダウンロードし、インストール
  2. Powershellを起動し、以下を実行
# バージョン確認
py --version

# pyコマンドで、任意のディレクトリに任意の名前(例として"C:\tmp\py_env")の仮想環境を作成
py -m venv "C:\tmp\py_env"

# 仮想環境をアクティベート
& "C:\tmp\py_env\Scripts\Activate.ps1"

# 必要ライブラリ をインストール
pip install pywinauto
pip install Pillow
pip install comtypes

# インストール確認
pip list

【Pythonスクリプト実行】

Powershellを起動し、以下を実行

# 仮想環境をアクティベート
& "C:\tmp\py_env\Scripts\Activate.ps1"

# スクリプトを実行
py "C:\script_path"

【スクリプト:基本構文】

#あなたの名前を変数に代入して、
#「こんにちは、〇〇さん!」と出力してください。
myname = "aki"
print(f"{myname}")

#りんごが3個、1個120円です。
#合計金額を計算して出力してください。
number = 3
price = 120
print(number * price)

#変数 x = 10 が5より大きい場合に「大きい」、
#そうでない場合に「小さい」と出力するプログラムを書いてください。
x = 10
if x > 5:
    print("大きい")
else:
    print("小さい")

#1から10までの数字を順に出力するプログラムを書いてください。
#pattern1
x = 1
while x < 11:
    print(x)
    x = (x + 1)

#pattern2
for x in range(1, 11):
    print(x)

#2つの数を引数にとって、その和を返す関数 add(a, b) を作ってください。
#return → 関数の外に値を返す
##### add は単独で使える関数
def add(a, b):
    return a + b

result = add(1, 3)
print(result)

#リスト fruits = ["apple", "banana", "orange"] の中の
# すべての要素を1つずつ出力してください。
fruits = ["apple", "banana", "orange"]
for x in fruits:
    print(x)

#メソッド = オブジェクトに結びついた関数 です。
#append() は リスト fruits に属している
#「メソッド = オブジェクト.操作()」という形になる
fruits.append("pear")
for x in fruits:
    print(x)


#リスト numbers = [3, 7, 2, 8, 4] の合計を計算して出力してください。
numbers = [3, 7, 2, 8, 4]
print(sum(numbers))

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?