p.drewello
p.drewello

Reputation: 95

In python, what does [None] do/mean during coding of class?

What does the [None] do in this code?

public class Example {                            //Java
     public Example (int _input, int _outputs){   //Java
          scratch = [None] * (_input + _outputs); //Python Code

I'm porting a python implementation into Java and need to better understand what this means. Many thanks for your help.

Upvotes: 0

Views: 341

Answers (3)

kindall
kindall

Reputation: 184091

[None] is a list containing one element, the singleton None, which is commonly used to represent "no value" in Python. This list is being multiplied by the sum of the number of inputs and outputs. The resulting list will have as many references to None as there are inputs and outputs.

Upvotes: 2

RiaD
RiaD

Reputation: 47619

[value] * number

means list of number elements, each of them is value.

So your code means list of (_input + _outputs) None's

null is closest thing to Python's None I know.

Upvotes: 1

inspectorG4dget
inspectorG4dget

Reputation: 113905

scratch = [None] * (_input + _outputs)

This makes a list of length _input + _outputs. Each element in this list is a None object.
This list is assigned to a variable, named scratch

Upvotes: 1

Related Questions