简体   繁体   中英

How do I convert 3 decimal inputs to float then to an integer all in the same line

如何以最优雅的方式从用户那里获取 3 个十进制输入,然后将它们转换为浮点数,然后将它们转换为整数

Translating your question literally (minus the elegant part), it would look like this

values = [ int(float(input("input> "))) for _ in range(3) ]

However, there is no point to convert first to float, just to truncate to an int when you could convert the input to an int directly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM