user14981754
user14981754

Reputation:

None in python array

arr=[1,2,3,4,5]
n=len(arr)
temp = n*[None]
flag = True
flag= bool(1-flag)

I'm new to python, so not sure what it really means. I want to know what all three lines of code do. Thank you

Upvotes: 0

Views: 5314

Answers (1)

Charlix2001
Charlix2001

Reputation: 21

The first line will create an array of five elements

    print (arr)
    [1, 2, 3, 4, 5] 

The second will make a variable named 'n' that will contain the number of elements in your array

print(n) 
5

The third line will create an array with a length of 5 that will only contain None.

None is used to define a variable so that it resets to a variable with no value. It is not similar to a NULL or an empty string, None is an object.

 print(temp)
 [None, None, None, None, None]

The last line will change your flag value to false. In standard binary conventions, True is equal to 1 and False is equal to 0. By subtracting a 1 with the flag value that is True, you are doing 1-1 which is equal to Zero. With bool(), you obtain a false.

  print(flag)
    False 

Upvotes: 2

Related Questions