python3

python3 で文字列を入力させて受け取る方法

投稿日:2020年11月28日 更新日:

C言語で scanf のようなものを作るには、python では input() で実現できる。

print('xの値を入力してください')
x = input()
print('xの値は ' + x)

結果

xの値を入力してください
234
xの値は 234

-python3
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

python3 で、pathlib を使ってファイルの拡張子を取得する方法

pathlib モジュールの stem を使う。 この書き方は、python 3.4 以降で使えるようになった。 https://docs.python.org/3/library/pathlib.h …

no image

python3 で、csv ファイルを読み込んで条件をみたす行の内容を表示する方法

csv.reader で読み込み、各行を読み込んで判定する。 例 import csv with open(‘data.csv’, ‘r’) as csv_file: reader = csv.rea …

no image

python3 でランダムな整数の配列を作る方法

random モジュールを使う。randint() の引数で、配列の最小値と最大値を指定できる。 例 import random random_arr = [random.randint(-2 …

no image

python でファイルを1行おきに読み込む方法

readline を使って次のように書く。 例 ファイル:data.txt # id name age 1 佐藤太郎 10 2 鈴木花子 18 3 坂本明美 21 4 松村光子 24 5 小川奏子 1 …

no image

matplotlib で、軸に垂直・平行な線を書く方法

axhline, axvline を使ってx,y軸に平行な線を描くことができる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot …