Python Random randint() Method
ตัวอย่าง
ส่งกลับตัวเลขระหว่าง 3 ถึง 9 (รวมทั้งสอง):
import random
print(random.randint(3, 9))
ความหมายและการใช้งาน
วิธี การrandint()
ส่งคืนองค์ประกอบที่เลือกจำนวนเต็มจากช่วงที่ระบุ
หมายเหตุ:เมธอดนี้เป็นนามแฝงสำหรับrandrange(start, stop+1)
.
ไวยากรณ์
random.randint(start, stop)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
start | Required. An integer specifying at which position to start. |
stop | Required. An integer specifying at which position to end. |