python - 如何将int变量转换为字符串
问题描述
这个问题是关于如何将 int 转换为字符串。我是编码新手,我不知道如何将 int 值转换为 str 值,因为在 python 中,我们不能将 int 值与字符串值结合起来。所以我们必须将 int 值转换为 string 。希望我的问题能帮助我自己和未来的程序员。
print("Type your age ")
character_age = input()
print("So your age is "+character_age)
print("If your father is 20 years older what will be your fathers age ?")
age_character = int(character_age)
print("Father's age is " +age_character)
解决方案
输入:
print("Type your age ")
character_age = input()
print("So your age is "+character_age)
print("If your father is 20 years older what will be your fathers age ?")
age_character = int(character_age)+20 #add 20 with character age
print("Father's age is " + str (age_character )) # convert back into string for print
输出:
Type your age
5
So your age is 5
If your father is 20 years older what will be your fathers age ?
Father's age is 25
推荐阅读
- angular - 使用 *ngFor 创建多个复选框
- r - 在 Stan 中开发非线性增长曲线模型的分层版本
- android - 使用 Android Studio 3.2 Canary 17 时出现 kotlin-android 错误
- node.js - npm install 不安装我的依赖项
- reactjs - 拥有 .bind() 的目的
- actionscript-3 - 在 AS3 中将影片剪辑拖到另一个影片剪辑上时使用 mouse_over
- oracle - 在 Oracle 的特定模式下限制 DROP 和 ALTER 表
- jpa - CDI 中@Transactional 的限制是什么?
- r - R:按 2 列分组,但仅当第 2 列不匹配时
- javascript - Javascript - 如何使用搜索输入过滤对象值并基于此获取其键?