Reputation: 53
q =["hello", "there"]
q.insert(2,"How r u")
print("Result : "),q
OUTPUT:
Result :
(None, ['hello', 'there', 'How r u'])
Why it prints None
?
Upvotes: 0
Views: 46
Reputation: 1231
Every list of var names in python are in reality a tuple, so:
a, b
is really (a, b)
so
print("Result : "),q
is a tuple of values (None, q)
Upvotes: 0
Reputation: 26039
Because print
returns None
.
For example:
>>> print(print(1))
1
None
First it prints value and then returns None
.
Explaining your code:
q =["hello", "there"]
q.insert(2,"How r u")
print(print("Result : "),q)
Steps:
Start from inner print
:
print("Result : ") # -> prints Result : and returns None
Now it becomes:
print(None, q) # -> prints None ['hello', 'there', 'How r u']
Upvotes: 1