首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用print()在变量前添加字符

如何使用print()在变量前添加字符
EN

Stack Overflow用户
提问于 2019-06-10 00:30:42
回答 1查看 115关注 0票数 0

我是使用3.7的Python新手,我正在尝试在整数变量前添加一个"$“。在执行了多次搜索之后,似乎有许多方法可以格式化字符串。我的目标是在print()中添加一个"$“。

我已经试过print('Total amount is' , houseAmount , ' of the house' , sep = ' $')了。但没那么走运。

代码:

houseAmount = float(300000)

hoa = float(550.4)

print('House amount is' , houseAmount , ' for the house.' , 'HOA amount for the house is' , hoa , 'every year') (I would like to add a "$" before "houseAmount" and "hoa")

结果

House amount is $300000 for the house. HOA amount for the house is $550.4 every year
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56516377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档