Intellipaat Back

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

I Googled it a lot but could not found it. I want to know the use of random.sample() method and what does it give? When should it be used and some example usage.

1 Answer

0 votes
by (106k points)
edited by

The random.sample() method Return a ‘k’ length list of unique elements chosen from the population sequence. Used for random sampling without replacement. You can see the code below:-

import random 

c = list(range(0, 15)) 

print(c)

random.sample(c, 5)

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
4 answers
asked Mar 31, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Feb 26, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...