xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to get random elements from a list in Python
Python Online Editor
Execute Code
More Python Sample Codes
import random #import to use random int_list = [1, 2, 3, 4, 5, 6, 7] # list of integer #sample() function selects 2 random elements from the list as a list random_sample_2 = random.sample(int_list, 2) # parameter 2 is used to get 2 elements print(random_sample_2) #sample() function selects 3 random elements from the list as a list random_sample_3 = random.sample(int_list, 3) # parameter 3 is used to get 3 elements print(random_sample_3) # Attn.: Click Execute Code button repeatedly and check the output.