python - TypeError:必须是 str,而不是 int Python3 问题
问题描述
第6行有什么问题:
name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff)
我不断收到错误:
TypeError: must be str, not int
大家一般是怎么调试的?我是编程新手。有没有办法确切地知道它想要字符串的位置?
解决方案
Python 无法自动将整数变量转换为字符串。
您需要将future
变量显式转换为str
如下类型:
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)
推荐阅读
- excel - GdiPlus.dll 经常导致 excel 2010 崩溃
- python - 具有私人要求的 pip install 失败
- flutter - 如何在颤动中检测 Listview 构建器/屏幕的半滚动?
- video - 在 H.264 视频的每一帧上隐藏数据
- javascript - 用js上传前预览图片
- action - 操作控制台分析数据丢失
- batch-file - 如果网络 RTO 后网络正常运行,如何自动执行批处理文件
- java - 未调用 Mockito 存根方法
- adapter - 在 BizTalk 2016 中为 WCF 自定义适配器创建发送处理程序时出错
- node.js - Node.js:在signedUrl字符串上的res.send在生产中返回{}