【问题标题】:how str() implement in python?str() 如何在 python 中实现?
【发布时间】:2019-07-11 00:48:30
【问题描述】:

节省和结果的定义

savings = 100
result = 100 * 1.10 ** 7

修复打印输出

print("I started with $" + savings+  " and now have $" + result+  " Awesome!")

pi_string的定义

pi_string = "3.1415926"

【问题讨论】:

  • 不清楚你的问题是什么,你能说得更具体点吗?
  • 您是否尝试过运行您的代码并查看它给出的错误?
  • 你不能连接 'str' 和 'int' 对象
  • @olivier,关闭为“不清楚你在问什么”

标签: python concatenation


【解决方案1】:

您可以像这样将ints 转换为strs:

print("I started with $" + str(savings)+  " and now have $" + str(result)+  " Awesome!")

或使用这样的字符串格式:

print("I started with ${} and now have ${} Awesome!".format(savings, result))

【讨论】:

    猜你喜欢
    • 2016-11-05
    • 1970-01-01
    • 2023-02-08
    • 2017-04-15
    • 2021-04-03
    • 2011-01-22
    • 2017-01-02
    • 2018-11-30
    • 2021-04-12
    相关资源
    最近更新 更多