Page 141 - Beginning Programming with Pyth - John Paul Mueller
P. 141

perform various types of comparisons.
In some cases, you use some fancy methods for performing comparisons in an application. For example, you can compare the output of two functions (as described in the “Comparing function output” section, later in this chapter). With Python, you can perform comparisons at a number of levels so that you can manage data without a problem in your application. Using these techniques hides detail so that you can focus on the point of the comparison and define how to react to that comparison rather than become mired in detail. Your choice of techniques for performing comparisons affects the manner in which Python views the data and determines the sorts of things you can do to manage the data after the comparison is made. All this functionality might seem absurdly complex at the moment, but the important point to remember is that applications require comparisons in order to interact with data correctly.
Understanding how computers make comparisons
Computers don’t understand packaging, such as functions, or any of the other structures that you create with Python. All this packaging is for your benefit, not the computer’s. However, computers do directly support the concept of operators. Most Python operators have a direct corollary with a command that the computer understands directly. For example, when you ask whether one number is greater than another number, the computer can actually perform this computation directly, using an operator. (The upcoming section explains operators in detail.)
Some comparisons aren’t direct. Computers work only with numbers. So, when you ask Python to compare two strings, what Python actually does is compare the numeric value of each character in the string. For example, the letter A is actually the number 65 in the computer. A lowercase letter a has a different numeric value — 97. As a result, even though you might see ABC as being equal to abc, the computer doesn’t agree — it sees them as different because the numeric values of their individual letters are different.
Working with Operators
  




























































































   139   140   141   142   143