python产生错误:can only concatenate str (not "int") to str

Posted wang509020--python学习者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python产生错误:can only concatenate str (not "int") to str相关的知识,希望对你有一定的参考价值。

代码为:

#!/usr/bin/python
# _*_ coding:utf-8_*_
# print("hello world!")
name = input("name:")
age = int(input("age:"))
print(type(age))
#print(type(age), type(str(age)))
home = input("home:")
print(type(home))
info3='''
---------info3 of ''' + name + ''' --------------
name: ''' + name + '''
age:''' + age + '''
home:''' + home + '''
--------end---------
'''
print(info3)

在使用python拼接进行格式化输出时出现如下错误:

Traceback (most recent call last):
  File "D:linuxpython	est2day1info.py", line 22, in <module>
    home:''' + home + '''
TypeError: can only concatenate str (not "int") to str

针对此问题,解决方法是:
主要是因为age的字段中使用int格式来验证,导致此问题。

age = input("age:")

以上是关于python产生错误:can only concatenate str (not "int") to str的主要内容,如果未能解决你的问题,请参考以下文章

python报错:only integer scalar arrays can be converted to a scalar index

成功解决TypeError: only size-1 arrays can be converted to Python scalars

only size-1 arrays can be converted to Python scalars

如何解决此滚动视图错误“ScrollView can host only one direct child”

关闭应用程序时多次出现错误“QObject::startTimer: QTimer can only be used with threads started with QThread”

andriod 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用(代码