What is the result of % in Python?

前端 未结 19 1700
粉色の甜心
粉色の甜心 2020-11-22 00:57

What does the % in a calculation? I can\'t seem to work out what it does.

Does it work out a percent of the calculation for example: 4 % 2

19条回答
  •  醉话见心
    2020-11-22 01:19

    % Modulo operator can be also used for printing strings (Just like in C) as defined on Google https://developers.google.com/edu/python/strings.

          # % operator
      text = "%d little pigs come out or I'll %s and %s and %s" % (3, 'huff', 'puff', 'blow down')
    

    This seems to bit off topic but It will certainly help someone.

提交回复
热议问题