[英]Can somebody explain the Output?
q =["hello", "there"]
q.insert(2,"How r u")
print("Result : "),q
OUTPUT: 输出:
Result :
结果:
(None, ['hello', 'there', 'How r u'])
(无,['hello','there','How r u'])
Why it prints None
? 为什么打印
None
?
print("Result : "),q
应该
print("Result : ", q)
Because print
returns None
. 因为
print
返回None
。
For example : 例如 :
>>> print(print(1))
1
None
First it prints value and then returns None
. 首先,它输出值,然后返回
None
。
Explaining your code : 解释您的代码 :
q =["hello", "there"]
q.insert(2,"How r u")
print(print("Result : "),q)
Steps : 步骤 :
Start from inner print
: 从内部
print
开始:
print("Result : ") # -> prints Result : and returns None
Now it becomes: 现在变成:
print(None, q) # -> prints None ['hello', 'there', 'How r u']
Every list of var names in python are in reality a tuple, so: 实际上,Python中的每个var名称列表都是一个元组,因此:
a, b
is really (a, b)
a, b
确实是(a, b)
so 所以
print("Result : "),q
is a tuple of values (None, q)
print("Result : "),q
是值的元组(None, q)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.