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:\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的更多相关文章
- Python基础学习Day3 数据类型的转换、int、str、bool、字符串的常用方法、for循环
一.数据类型的转换 常用的是:int 转str.str转int.int转bool 时 非零即为 True . # 数据类型之间转换 ***** # int <--> str str(i ...
- 【问题记录】Python运行报错:can only concatenate str (not "int") to str
自己总是写程序时候用 + 拼接的时候忘记变量类型要一致,如下面 frame_num = "1" for i in range(1, frame_num + 1, 1): self. ...
- 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 ...
- python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)
当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int' 如下图: 这是因为input ...
- python的错误和异常
python错误和异常 错误 错误分为语法错误和逻辑错误 语法错误 >>> if File "<stdin>", line 1 if ^ Syntax ...
- python 处理中文遇到的编码问题总结 以及 字符str的编码如何判断
如何处理中午编码的问题 Python的UnicodeDecodeError: 'utf8' codec can't decode byte 0xxx in position 这个错误是因为你代码中的某 ...
- Python的基础类型(int,bool,str):
Python的基础类型(int,bool,str): 1.int -------> 整形:主要用力进行数字计算 2.string ------>字符串:可以保存少量数据并进行相关的操作 3 ...
- python的str,unicode对象的encode和decode方法, Python中字符编码的总结和对比bytes和str
python_2.x_unicode_to_str.py a = u"中文字符"; a.encode("GBK"); #打印: '\xd6\xd0\xce\xc ...
- python基础与数据类型(int, float, str, list)
目录 python多版本共存 在cmd窗口进入不同版本的python环境 在pycharm中切换不同的版本 python语法之注释 python变量与常量 变量 变量的本质 变量的命名规范 常量 py ...
随机推荐
- IIS中应用Application Request Route 配置负载均衡
转自:https://blog.csdn.net/wucong60/article/details/84930234 简介ApplicationRequest Route(后面简称为ARR)是一个寄宿 ...
- vue知识点积累
vue中 列表组件写key,起作用是什么? <ul> <li v-for="item in items" :key="item.id"> ...
- 【计算机视觉】深度相机(五)--Kinect v2.0
原文:http://blog.csdn.NET/qq1175421841/article/details/50412994 ----微软Build2012大会:Kinect for Windows P ...
- U盘自动复制文件
1.建立一个文本文档,WIN+R 里面打NOTEPAD ,或者自己新建一个都一样. 2.把下面的代码复制进去 set fso=createobject("scripting.filesyst ...
- FTP服务器搭建基础工具:Serv-U 14.0.2使用教程
安装教程 1.在本站下载好压缩包,将文件解压,双击运行“ServUSetup官方原版程序.exe”程序,弹出语言选择框,选择“中文(简体)”,点击“确定”开始安装 2.点击“下一步”进行安装 ...
- 使用nginx构建限频、限速、限并发的应用保护层
使用nginx构建限频.限速.限并发的应用保护层 nginx本身提供了基础的限频.限速.限并发连接等能力. 限频 基于uri等限制某一个客户端,某类客户端持续时间段内建立连接的次数. 限速 限制客户端 ...
- [转帖]K8s 学习者绝对不能错过的最全知识图谱(内含 58个知识点链接)
K8s 学习者绝对不能错过的最全知识图谱(内含 58个知识点链接) https://www.cnblogs.com/alisystemsoftware/p/11429164.html 需要加强学习 ...
- flannel vxlan工作基本原理及常见排障方法
写在前面 最近用kubeadm鼓捣了几个cluster集群测试用,网络用的flannel.因为这些机器都不是纯净的环境(以前部署过其他的k8s或者有一些特别的设置),所以部署起来遇到了很多问题.看了下 ...
- EXCEL 查找某个字符在字符串中最后一次出现的位置
在EXCEL文档里想从很长的文件路径中取得文件名,[数据]→[分列]是个不错的选择,但用函数会显得更高大上一些. 首先,需要获取最后一个"\"所在的位置. 方法1: FIND(&q ...
- 为什么fastjson字段为null时不输出空字符串?
为什么fastjson字段为null时不输出空字符串? Map < String , Object > jsonMap = new HashMap< String , Object& ...