Python Random randrange () Methode
Beispiel
Geben Sie eine Zahl zwischen 3 und 9 zurück:
import random
print(random.randrange(3, 9))
Definition und Verwendung
Die randrange()
Methode gibt ein zufällig ausgewähltes Element aus dem angegebenen Bereich zurück.
Syntax
random.randrange(start, stop, step)
Parameterwerte
Parameter | Description |
---|---|
start | Optional. An integer specifying at which position to start. Default 0 |
stop | Required. An integer specifying at which position to end. |
step | Optional. An integer specifying the incrementation. Default 1 |