【问题标题】:How can I picking numbers of numbers in python? [closed]如何在 python 中选择数字的数量? [关闭]
【发布时间】:2021-05-16 10:58:21
【问题描述】:

如果输入数字,我需要选择前 3 个数字。 示例;

23456.43 = 234

7348593.8304853 = 734

1.097493 = 109

27.7481 = 277

如何在 Python 中做到这一点?

【问题讨论】:

  • str(your_input).replace('.','')[:3]?
  • 你知道输入是浮点数还是字母?
  • Stack Overflow 并非旨在取代现有的教程和文档。请重复有关字符串处理的材料。
  • 这能回答你的问题吗? Get most significant digit in python

标签: python time-series artificial-intelligence data-mining finance


【解决方案1】:

试试这个

number  = 23.4563
x  = int(str(number).replace('.', '') [:3])
print(x)

输出:

234

【讨论】:

    猜你喜欢
    • 2014-12-27
    • 2015-12-07
    • 1970-01-01
    • 2018-10-02
    • 2020-05-17
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多