Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我一直收到打字错误:';str';对象不可调用,我不确定如何修复它_Python_String_Helper - Fatal编程技术网

Python 我一直收到打字错误:';str';对象不可调用,我不确定如何修复它

Python 我一直收到打字错误:';str';对象不可调用,我不确定如何修复它,python,string,helper,Python,String,Helper,这是我写的代码,它应该告诉我之后圆的半径,但是我一直得到一个错误 PI = 3.141593 radius_p = float(input('radius')) perimeter = 2 * PI * radius_p print('perimeter: ') + str(perimeter) # Ask the user for the radius of the room # Calculate the perimeter # Print the perimeter this is wh

这是我写的代码,它应该告诉我之后圆的半径,但是我一直得到一个错误

PI = 3.141593
radius_p = float(input('radius'))
perimeter = 2 * PI * radius_p
print('perimeter: ') + str(perimeter)
# Ask the user for the radius of the room
# Calculate the perimeter
# Print the perimeter

this is what I get after 

```
TypeError                                 Traceback (most recent call last)
<ipython-input-80-ba1678e7ffca> in <module>()
      2 radius_p = float(input('radius'))
      3 perimeter = 2 * PI * radius_p
----> 4 print('perimeter: ') + str(perimeter)
      5 # Ask the user for the radius of the room
      6 # Calculate the perimeter

TypeError: 'str' object is not callable
PI=3.141593
半径p=浮动(输入(“半径”)
周长=2*PI*半径
打印('周长:')+str(周长)
#询问用户房间的半径
#计算周长
#打印周长
这就是我想要的
```
TypeError回溯(最近一次调用上次)
在()
2半径p=浮动(输入(“半径”)
3周长=2*PI*半径
---->4打印(周长:)+str(周长)
5.询问用户房间的半径
6#计算周长
TypeError:“str”对象不可调用

问题在于
print()
函数将值打印到shell或控制台,而不返回任何内容。这就是为什么当您将返回
NoneType
print()
与字符串格式的
str()
函数连接时,会导致错误。Python不允许对不同类型的变量执行concat操作。这就是您应该更正代码的地方

PI = 3.141593
radius_p = float(input('radius'))
perimeter = 2 * PI * radius_p
print('perimeter:', str(perimeter))
您应该通过输入4获得与我在下面所做的一样的输出。


注意:如果问题仍然存在,则您需要与我们共享完整代码,因为您可能将str对象用作变量名,这是不正确的。

打印语句行的语法是错误的。应该是

打印('周长:'+str(周长))

若仍然出现错误,只需检查将周长的字符串值指定给另一个变量并打印即可

newperi=str(周长)

打印('周长:'+newperi)


print('permiture:'+str(permiture))
@SeanHsieh我把它改成了这个,但还是出现了同样的错误我想问题是你在代码中的某个地方使用了
str
作为变量名。不要使用内置名称作为变量名。那么,既然你接受了答案,为什么会出现同样的错误呢?谢谢你,这是有效的。由于某种原因,我使用的程序无法正常工作