English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this example, you will learn how to generate random numbers in Python.
To understand this example, you should understand the followingPython programmingTopic:
To generate random numbers in Python, please use the randint() function. This function is inrandom moduleDefinition.
# Program generates a random number between 0 and9between random numbers # Import the random module import random print(random.randint(0,9))
Output result
5
Please note that since this program generates a range of 0 and9The random number, so we may get different outputs. The syntax of this function is:
random.randint(a,b)
This will return a N containing a range of numbers [a, b], that is, a <= N <= b, and the range includes the endpoints.