The Ord () function is mainly used to return the ASCII code of the corresponding character, and Chr () is used mainly to denote the ASCII code corresponding to the character of his input when the number, can be in decimal or hexadecimal.
Example: Print ord (' a)
#97
Print Chr (97)
#a
Print Chr (0x61)
#a
A simple program to use flexibly.
str1= ' asdfasdf123123 '
For I in Rang (Len (str1)):
Print Chr (ord (Str1[i))-1)
#以上程序主要实现对字符串str1里面所有的字符, convert the characters in the ASCII code to one smaller than them.
Title: Two table tennis team to play, each out three people. Team A for A,b,c three, team B for X, Y, z three people. Have drawn lots to determine the contest list. Someone asked the team for a list of matches. A says he does not compare with X, C says he does not compare with x,z, please compile the procedure to find out the list of the three teams.
For I in Range (Ord (' X '), ord (' z ') + 1): for J in Range (Ord (' X '), ord (' z ') + 1): if I! = J: for K in range (Ord (' X '), Ord (' z ') + 1): if (i! = k) and (J! = k): if (i! = Ord (' x ')) and (k! = Ord (' x ')) and (k! = Ord (' z ')): Print ' Order is a--%s\t B--%s\tc--%s '% (Chr (i), Chr (j), Chr (k))
Python ord () and Chr () usage and differences