Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I actually understand that the codes underneath create a random position from (0,1) to (48,48). I might want to comprehend the procedure used. Was that tuple comprehension? Anyone, help me guys.

import random

BOARD_SIZE=(48,48)

position = tuple(random.randrange(BOARD_SIZE[i]) for i in (0,1))

print(position)

1 Answer

0 votes
by (26.4k points)
edited by

Here, you've used tuple comprehension.

The code is quite direct. First, you characterize BOARD_SIZE. Then, the first value is the upper bound of the primary value in the position, the same applies for the subsequent one.

Then, the output is (x,y). Here, x and y were random values in range(48)

Interested to learn Python in detail? Come and Join the Python course.

For more details, do check out the below video tutorial...

Related questions

0 votes
1 answer
asked Sep 10, 2019 in Python by Sammy (47.6k points)
+1 vote
1 answer
asked Jul 31, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer
0 votes
4 answers
asked Mar 31, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.6k points)

Browse Categories

...