Reputation: 95
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
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
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
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