グローバル変数とローカル変数で同じ名前の変数を使うことができる。
例
x = 10
def myfunc():
x = 20
print('関数内: x = '+str(x))
myfunc()
print('外側: x = ' + str(x))
結果
関数内: x = 20 外側: x = 10
雑記
投稿日:2020年12月4日 更新日:
グローバル変数とローカル変数で同じ名前の変数を使うことができる。
x = 10
def myfunc():
x = 20
print('関数内: x = '+str(x))
myfunc()
print('外側: x = ' + str(x))
関数内: x = 20 外側: x = 10
執筆者:seyanen
関連記事
matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法
pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …
C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …
plot.subplots() でグラフの縦方向と横方向の数を指定する。 例 import numpy as np from matplotlib import pyplot as plt x1 = …
os.mkdir() 関数を使う。 すでにフォルダが存在している場合は、エラーを表示する。 例 import os folder_name = ‘./python_create_folder’ try …
matplotlib で、粗い刻みと細かい刻みの目盛りを表示する方法
set_major_locator で粗い刻みの目盛りを調整する。 set_minor_locator で、細かい刻みの目盛りを調整する。 以下の例で set_major_formatter は、表示 …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。