Is there an operator to calculate percentage in Python?

后端 未结 5 661
予麋鹿
予麋鹿 2020-12-23 19:27

I\'ve recently learned that the \" % \" sign is used to calculate the remainder of an integer in Python. However I was unable to determine if there\'s another operator or me

5条回答
  •  臣服心动
    2020-12-23 19:44

    Very quickly and sortly-code implementation by using the lambda operator.

    In [17]: percent = lambda part, whole:float(whole) / 100 * float(part)
    In [18]: percent(5,400)
    Out[18]: 20.0
    In [19]: percent(5,435)
    Out[19]: 21.75
    

提交回复
热议问题