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 a random number in Python, please use the randint() function. This function is inIn the random moduleDefinition.
# The 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 random number between 0 and9The random number, so we may get different outputs. The syntax of this function is:
random.randint(a,b)
This will return a number N within the range [a, b], that is, a <= N <= b, including the endpoints of the range.