简体   繁体   English

为什么当我打印 python 语句时, ( ) 也会被打印出来?

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

相关问题 为什么第一个打印语句的字符串会打印在 python 中? - Why does the first print statement's string gets printed in python? 当你在 python 中打印某个类的对象时会打印什么? - What gets printed when you print a object of some class in python? 为什么当我输入 7 、 8 和 9 时会打印“Fail”? - Why does "Fail" gets printed when I input 7 , 8 and 9? 为什么当我尝试打印列表时,Google colab 中打印的是“None”? - Why `None` is printed in Google colab when I try to print a list? 为什么在python中运行以下代码片段时会打印20 - Why 20 gets printed when we run the following code snippet in python 如何在 Python 中的 try/except 语法中打印除语句而不是下面的错误 - How can I get print except statement printed instead of an error below in try/except syntax in Python 如果if陈述不应将2印刷为质数,为什么 - why is 2 printed as a prime when if statement says it should not be Python 2.7.8打印语句“语法错误:无效语法”在终端(ubuntu 14.04)但在vim上运行良好,为什么? - Python 2.7.8 print statement “Syntax Error: invalid syntax” in terminal (ubuntu 14.04) but running well on vim, why? 为什么在我编写然后在执行简单计算的 python 中使用 if 语句打印时没有显示任何内容? - Why do I get none displayed when I write and then print using if statement in python that does simple computation? 获取一个打印语句两次打印一个值的不同输出,python - Getting a print statement printed twice with different outputs for one value, python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM