📅  最后修改于: 2023-12-03 15:34:37.349000             🧑  作者: Mango
random.randint()
in Pythonrandom.randint(a, b)
is a Python function that returns a randomly selected integer from the range a
to b
(inclusive).
Here's an example usage:
import random
random_number = random.randint(1, 10)
print(f"The random number is {random_number}")
This will output a random number between 1 and 10, inclusive.
The syntax for random.randint()
is:
random.randint(a, b)
a
- the lower bound of the rangeb
- the upper bound of the rangerandom.randint()
returns a randomly selected integer between a
and b
, inclusive.
Here's another example:
import random
magic_number = random.randint(100, 200)
print(f"The magic number is {magic_number}")
This will output a random number between 100 and 200, inclusive.
random.randint()
is a useful function when you need a random integer within a specified range. It's easy to use and can be very versatile.