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 ...
随机推荐
- sonar:sonarqube6.7.6与mysql5.7版本不匹配
问题 更换sonarqube的数据库为mysql后,启动sonarqube,提示Database was upgraded to a more recent of SonarQube. 解决: 将so ...
- OPC Utgard的数据访问方式
1.同步读取某个点位的值 Item项的read()方法 Server server = new Server(BaseConfiguration.getCLSIDConnectionInfomatio ...
- 解决升Win10系统后VMware虚拟机不能联网的问题
刚升级到Win10系统,打开虚拟机发现不能联网,其实是系统服务项里缺少两个用到的服务,不能联网了,下面教大家解决联网问题. 1.打开VMware虚拟机主页,点击“编辑——虚拟网络编辑器”. 2.点击左 ...
- 通过JS动态追加标签,以父评论子评论为例
以下代码前后端交互以Django模板语法为例 先来以伪代码来示意用法: HTML部分: JS动态插入部分代码: 运行之后我们来浏览器看检查打印的内容: 看插入前后打印结果我们可以得知 $title[0 ...
- php静态调用非静态方法
<?php /** * php静态调用非静态方法 * author: 百里 * Date: 2019/7/18 * Time: 17:28 */ function dump(...$var) { ...
- LC 394. Decode String
问题描述 Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], wh ...
- DAG添边定理
让DAG变成强连通就是把尾和头连起来,也就是入度和出度为0的点,添的边数:max(num_in==0,num_out==0)
- sql server 数据库中明明有值但是查询怎么都查不到值
产生原因是因为编码问题 数据库是英文版 但是数据库中数据又是中文的 所以查询中文时需要加上N select * from customer where Username=N'张三'
- 为Vim 添加vimgdb支持
为Vim 添加vimgdb支持 1. 下载最新的vim74的源码包 wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2 2.下载vimgdb- ...
- for循环中的闭包
// 问题1:判断下面一段代码运行的结果是什么? var data = [] for (var i = 0; i < 3; i++) { data[i] = function() { conso ...