代码为:

#!/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:")

python产生错误:can only concatenate str (not "int") to str的更多相关文章

  1. Python基础学习Day3 数据类型的转换、int、str、bool、字符串的常用方法、for循环

    一.数据类型的转换 常用的是:int 转str.str转int.int转bool 时   非零即为 True . # 数据类型之间转换 ***** # int <--> str str(i ...

  2. 【问题记录】Python运行报错:can only concatenate str (not "int") to str

    自己总是写程序时候用 + 拼接的时候忘记变量类型要一致,如下面 frame_num = "1" for i in range(1, frame_num + 1, 1): self. ...

  3. TypeError: can only concatenate str (not "int") to str解决方式

    使用format函数解决问题 for page in range(1,pagebox+1): url = "https://www.dd373.com/s/rbg22w-x9kjbs-wwf ...

  4. python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)

    当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int' 如下图: 这是因为input ...

  5. python的错误和异常

    python错误和异常 错误 错误分为语法错误和逻辑错误 语法错误 >>> if File "<stdin>", line 1 if ^ Syntax ...

  6. python 处理中文遇到的编码问题总结 以及 字符str的编码如何判断

    如何处理中午编码的问题 Python的UnicodeDecodeError: 'utf8' codec can't decode byte 0xxx in position 这个错误是因为你代码中的某 ...

  7. Python的基础类型(int,bool,str):

    Python的基础类型(int,bool,str): 1.int -------> 整形:主要用力进行数字计算 2.string ------>字符串:可以保存少量数据并进行相关的操作 3 ...

  8. python的str,unicode对象的encode和decode方法, Python中字符编码的总结和对比bytes和str

    python_2.x_unicode_to_str.py a = u"中文字符"; a.encode("GBK"); #打印: '\xd6\xd0\xce\xc ...

  9. python基础与数据类型(int, float, str, list)

    目录 python多版本共存 在cmd窗口进入不同版本的python环境 在pycharm中切换不同的版本 python语法之注释 python变量与常量 变量 变量的本质 变量的命名规范 常量 py ...

随机推荐

  1. socket之IO多路复用

    概述 目的:同一个线程同时处理多个IO请求. 本文以python的select模块来实现socket编程中一个server同时处理多个client请求的问题. web框架tornado就是以此实现多客 ...

  2. 重写equals方法需要知道的事

    重写equals方法 相信在每个人都有过重写过java的equals的方法的经历.这篇博文就从以下几个方面说明重写equals方法的原由,与君共进步. 一 为什么要重写equals方法 首先我们了解e ...

  3. http与https的主要区别

    HTTP与HTTPS的主要区别如下: 1.https协议需要到ca申请证书,一般免费证书较少,因而需要一定费用. 2.http是超文本传输协议,信息是明文传输,https则是具有安全性的ssl加密传输 ...

  4. std::replace函数

    需包含头文件#include <algorithm> template <class ForwardIterator, class T> void replace (Forwa ...

  5. JavaScript里的类和继承(转)

    转自: http://www.h5cn.com/js/jishu/2016/0121/17634.html js与大部分客户端语言有几点明显的不同: JS是 动态解释性语言,没有编译过程,它在程序运行 ...

  6. python一些小知识点is和编码

    dic = { "name":["alex", "wusir", "taibai"], 'py9':{ "ti ...

  7. Own MusicPlayer隐私策略

    本地音乐播放器 此为Own MusicPlayer本地音乐播放器的隐私策略,本隐私策略内容会不定期更新,以最新内容为主. 若您已经阅读并了解以下内容后,并继续使用该软件,即表示您已同意该协议. 访问权 ...

  8. 【AtCoder】M-SOLUTIONS Programming Contest

    M-SOLUTIONS Programming Contest A - Sum of Interior Angles #include <bits/stdc++.h> #define fi ...

  9. python 修改文件的创建时间、修改时间、访问时间

    目录 python 修改文件创建.修改.访问时间 方案一 方案二(无法修改文件创建时间) python 修改文件创建.修改.访问时间 突如其来想知道一下 python 如何修改文件的属性(创建.修改. ...

  10. Python 变量作用域与函数

    Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...