Create a week10 subdirectory in your cs21/class directory by running update21:
$ update21 $ cd $ cd cs21/class/week10
Binary Search
Sorting
$ man asciiUse the arrow keys to navigate, and 'q' to quit.
You should never memorize the ascii encoding, but it is important to know that the encodings for 'a' to 'z' are contiguous, as are 'A' to 'Z' and '0' to '9'. Internallly, python uses the ascii encoding of characters to compare strings. For example, for the following expression:
"ant" == "any"Python first comapares the ascii values the first character in each string (97 for 'a' to 97 for 'a'), since they are equal, python then compares the ascii value of the second character in each string (110 for 'n' to 110 for 'n'), since they are equal, python then compares the ascii value of the third character in each string (116 for 't' to 121 for 'y'), since the ascii values are not equal, python evaluates the expression to False.
The ascii encoding also explains why the following relational expressions evaluate to True:
"Zoo" < "ant" "zoo" > "ant"because the ascii encoding for 'Z' is less than that for 'a' (90 vs. 97) the string "Zoo" is less than the string "ant", and because the ascii value for 'z' is greater than for 'a' (122 vs. 97) the string "zoo" is "Zoo" < "ant" greater than the string "ant".
You can use the ord function to get the ascii value for any character, and the chr function to get the character string for any numeric ascii value:
print ord('a') # prints 97 print chr(99) # prints the string c