How can I add an element to the list in python when I create it using random.choice and a reason?

For example, I do this:

 numbers = [1, 2, 3, 4] other_numbers = [] print(other_numbers.append(ramdom.choice(numbers))) 

It returns None .

So how can I make it so that I pin this element and add it to the list

  • I need to display a random letters label and then compare these letters from the tablet with other word lists, if there is an alternative way to do this, I will be very happy to hear it)) - Bernard
  • None returns the append method. Put the choice result into the variable, accept the variable and add it to the list - gil9red

2 answers 2

My version looks like this:

 import random numbers = [1, 2, 3, 4] other_numbers = [] r_number = random.choice(numbers) other_numbers.append(r_number) print(r_number) 

    You must first save the generated element to a variable. And then you can separate this element by separate actions, and then print:

     import random numbers = [1, 2, 3, 4] other_numbers = [] elem = random.choice(numbers) other_numbers.append(elem) print(elem)