[英]Why when I print a python statement, ( ) gets printed as well?
if len(all_stalls) == 0:
print("No stalls found with given keywords.")
# Print all stalls that match the keywords
else:
print ("Food Stalls Found:", len(all_stalls))
Output: ('Food Stalls Found:', 10) ==> why are there brackets around? Output: ('Food Stalls Found:', 10) ==> 为什么周围有括号?
You are in python2.你在python2中。
ubuntu@ubuntu-VivoBook-ASUSLaptop-X530FN-S530FN:~$ python
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Food Stalls Found:", 10)
('Food Stalls Found:', 10)
>>>
[2]+ Stopped python
ubuntu@ubuntu-VivoBook-ASUSLaptop-X530FN-S530FN:~$ python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Food Stalls Found:", 10)
Food Stalls Found: 10
>>>
You are using Python 2 where print is not a function.您正在使用 Python 2,其中 print 不是 function。 And when you call it like that with ()
, it gets interpreted as tuple.当你用()
这样调用它时,它会被解释为元组。
So, either you use所以,要么你使用
print "Food Stalls Found:", len(all_stalls)
or:或者:
from __future__ import print_function
print ("Food Stalls Found:", len(all_stalls))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.