python - 如何在python中将美国货币转换为字符串
问题描述
我想用逗号将元组值转换为python中的字符串。Ex Input: 3,500.60 and output should be 3,500.6(string type)
value=3,500.60
s=str(value)
这返回(3, 500.6)
但我想要3,500.6
可能吗?
解决方案
我问了一个单行表达式,它给出了这样的输出。无论如何,这个解决了我的问题。
value=3,500.60
b=''
for i in str(value):
if not i in (' ','(',')'):
b+=i
print(b)
更新
这就是我想要的:方法1:
print(str(map(lambda x:x if x not in ('(',')') else '',[i for i in value])).strip('[]').replace(' ',''))
方法二:
print(str(value).strip('()').replace(' ',''))
他们都给出了结果3,500.6
推荐阅读
- for-loop - 我的 DPC++ 代码没有编译为我在下面说明的循环,为什么?
- reactjs - GraphQL 保存表单
- ansible - 在滚动部署中导入 playbook
- memory - Box::pin() 与 Pin::new_unchecked()
- javascript - 如何在不使用 websockets 加密的情况下在节点 js 中创建基本身份验证系统?
- javascript - npm start 在启动时失败
- python - 从具有特定条件的列表列表中创建字典
- c++ - 如何将一个数字分成 1 字节的块以通过 C++ 中的串行蓝牙发送
- javascript - React:如何在 App.js 中重新渲染状态变化的路由
- bash - 使用 systemctl 作为服务运行时优雅退出 bash 脚本