0

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.

2
  • Not worthy of being an answer, but in many cases, I view None as being null. Commented Jul 26, 2013 at 22:01
  • What kind of data must be stored in scratch variable? Commented Jul 26, 2013 at 22:07

3 Answers 3

2

[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.

Sign up to request clarification or add additional context in comments.

Comments

1
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

Comments

1
[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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.