You can download this code by clicking the button below.
This code is now available for download.
The function compares the ASCII values of two strings in order and returns the difference between them. If either string is empty or they have different lengths, it returns 0.
Technology Stack : Built-in functions: ord(), string comparison
Code Type : Function
Code Difficulty : Intermediate
def aordiff(arg1, arg2):
"""
比较两个字符串的ASCII值顺序并返回它们之间的差值。
"""
if arg1 == "" or arg2 == "":
return 0
elif arg1 < arg2:
return ord(arg2[0]) - ord(arg1[0])
else:
return ord(arg1[0]) - ord(arg2[0])