Sunday, January 26, 2025
HomeQ&AWhat Is randint() Function in Python?

What Is randint() Function in Python?

The randint() function in Python is part of the random module, and it is used to generate a random integer within a specified range. The function takes two arguments: the start and the end of the range (inclusive).

See also  What Does the Phrase “Keep Your Friends Close” Mean?

Syntax:

import random
random.randint(a, b)
  • a: The lower bound (inclusive).
  • b: The upper bound (inclusive).

Example:

import random

# Generate a random integer between 1 and 10 (both inclusive)
random_number = random.randint(1, 10)
print(random_number)

In this example, random.randint(1, 10) will generate a random number between 1 and 10, inclusive.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x