How to show decimal point only when it's not a whole number?

后端 未结 3 1088
半阙折子戏
半阙折子戏 2020-12-03 15:14

I have Googled, but couldn\'t find a proper answer to this.

Let\'s say we have floats and we get their averages. Their averages are like this:

3.5
2.         


        
3条回答
  •  醉酒成梦
    2020-12-03 16:04

    Technically, if you have floats and get their averages, you SHOULD get floats back. But if you just want to print them, the following should work well:

    print('{} {} {} {}'.format(3.5, 2.5, 5, 7))
    

提交回复
热议问题