python3

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

投稿日:2020年12月15日 更新日:

random モジュールを使う。

randint() の引数で、配列の最小値と最大値を指定できる。

import random
random_arr = [random.randint(-20,20) for _ in range(30)]
print(random_arr)

結果

[-17, 18, 9, -3, 7, -7, 14, -14, -10, 9, 3, 5, -12, -4, 18, -7, 20, 8, -18, 18, 17, 0, -20, -8, 2, -5, 16, 2, -12, 8]
[商品価格に関しましては、リンクが作成された時点と現時点で情報が変更されている場合がございます。]

ゴールデンカムイ 1【電子書籍】[ 野田サトル ]
価格:564円(税別、送料別)(2020/12/24時点)

楽天で購入

-python3
-

執筆者:


comment

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

関連記事

no image

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

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

no image

matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法

pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …

no image

matplotlib で、y軸に二種類の軸を設定する方法

y軸に、2種類のグラフを異なるスケールでプロットする。 matplotlib axes の twinx() を使う。 https://matplotlib.org/stable/api/_as_gen …

no image

python3 で辞書からタプルを作成する

辞書に対して、items() メソッドを使うと、タプルを作成することができる。 例 cities = {‘東京’:1000,’大阪’:700, ‘広島’:100} for a,b in cities. …

no image

python3 で、リストを pop したものの返り値

リストを pop すると、 pop された値が返される。 例 plant_1 = [’pumpkin’, ‘ginger’, ‘potato’] plant_2 = [] print( …