python错误“类型错误:nonetype对象不可调用" [英] python error "typeerror: nonetype object not callable"

查看:108
本文介绍了python错误“类型错误:nonetype对象不可调用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 python 制作一个简单的计时器脚本.我看到很多其他人也有这个错误,但我认为我的错误可能有所不同,因为我是 Python 新手:

I'm trying to make a simple timer script in python. I see a lot of other people have had this error too, but I think my error may be different because I'm new to python:

time=60
from time import sleep
while (time>0):
    print ("you have") (time) ("seconds left")
    time-=1
    sleep(1)

结果如下:

<代码>>>>你有回溯(最近一次调用最后一次):文件H:\counter.py",第 4 行,在 <module> 中打印(你有")(时间)(剩余秒数")TypeError: 'NoneType' 对象不可调用

谁能发现这个错误?使用 %s 以及在时间变量周围使用 + 和 str() 也让我失败

Can anyone spot this error? using %s has also failed me along with using +'s and str() around the time variable

推荐答案

一个函数只能有一组参数.

A function can have only a single set of arguments.

print_statement = "you have" + str(time) + "seconds left"
print(print_statement)

上面的代码应该可以工作.

The above code should work.

这篇关于python错误“类型错误:nonetype对象不可调用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆