python中使用的'%'符号究竟是什么?

时间:2017-07-05 20:47:49

标签: python python-3.x

这是一个简单加密方法的代码。

if character in alphabet:
    position=alphabet.find(character)
    newPosition=(position-key)%26  # here 
    newCharacter=alphabet[newPosition]
    print("The encrypted character is: " + newCharacter)
    newMessage += newCharacter
    print(newMessage)

1 个答案:

答案 0 :(得分:3)

代码中的%符号是 modulo 运算符 - 整数除法后的余数。 E. g。

    13 % 5

给出结果3

13除以52,其余为3

相关问题