Home > Article > Backend Development > What does sample mean in python?
sample is a function in the random module
The expression is:
random.sample(sequence, k)
its function is Randomly obtain fragments of the specified length from the specified sequence and arrange them randomly, and return the result in the form of a list . Note: The sample function will not modify the original sequence.
For example:
Other usage methods in the random module
1, random.random Randomly generate [0.1) floating point number
2. random.uniform
The prototype is: random.uniform(a, b), which is used to generate a random number of character points within a specified range. One of the two parameters is the upper limit. , one is the lower limit. If a > b, the generated random number n: a
3. andom.randint
The prototype is: random.randint(a, b), used to generate an integer within a specified range. The parameter a is the lower limit, the parameter b is the upper limit, and the generated random number n: a
4, random.choice
The prototype is: random.choice(sequence). The parameter sequence represents an ordered type. Let me explain here: sequence is not a specific type in python, but generally refers to a series of types. List, tuple, and string all belong to sequence (dictionaries and collections are unordered)
5. ****random.shuffle
The prototype is: random.shuffle(x[, random]) , used to scramble the elements in a list.
Related learning recommendations: python tutorial
The above is the detailed content of What does sample mean in python?. For more information, please follow other related articles on the PHP Chinese website!