「Python」randint()関数でリストの値をランダムに表示する

2020年10月21日

構文
randint(a,b)
引数をa以上b以下
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import random
cft = ["A001","B002","C003","D005","E006"]
n = random.randint(0,4)
print(cft[n])
# coding: utf-8 import random cft = ["A001","B002","C003","D005","E006"] n = random.randint(0,4) print(cft[n])
# coding: utf-8
import random

cft = ["A001","B002","C003","D005","E006"]

n = random.randint(0,4) 

print(cft[n])

 

Python

Posted by arkgame