代码为:
#!/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:\linux\python\test2\day1\info.py", line 22, in <module>
home:''' + home + '''
TypeError: can only concatenate str (not "int") to str
针对此问题,解决方法是:
主要是因为age的字段中使用int格式来验证,导致此问题。
age = input("age:")
原文地址:https://www.cnblogs.com/wang50902/p/11660761.html
时间: 2024-10-08 23:22:16