You are viewing a single comment's thread. Return to all comments →
The %26 is used in order to determine the shifting since there are only 26 letters of the alphabet. For example: In the above code, when looking at a letter of the string, the letter is converted to it's ascii value with ord( ). Then in the return statement, num-97+k determines the new number that we are going to shift to. However, if this number is say ...27, there is no 27th letter of the alphabet so 27%26 = 1, which means we start over at the 1st letter of the alphabet. The additional +97 or +65 will account for the respective uppercase or lowercase ascii values.
As for the * in the print statement, its used to 'unpack' the list that has been created with a (sep='') separation of non-spaces. This means that the brackets are removed and the individual contents of the list will be printed with no space between them. (Just like the desired output looks)