Custom Rich-Text Page
total_price = item_price*(1+tax_rate/100) In this expression, we first evaluate the contents of the parentheses before multiplying. In evaluating the contents of the parentheses, we first perform the division, since that has higher precedence than addition. Thus, for example, if tax_rate is 7, then we first take 7/100 to get .07 and then add that to 1 to get 1.07. Then, the current value of item_price is multiplied by 1.07, which is then assigned to total_price.
----------
Integer division (/ /) Python provides a second division operator, //, which performs integer division. In particular, the answer of an integer division operation is always an integer. In particular, a//b is defined as the largest number of whole times b divides into a. Here are a few examples of evaluating expressions with integer division: >>> 25//4 6 >>> 99//100 0 >>> 99//100 0 >>> -17//18 -1 >>> -1//10000000 -1 >>> -99999999//99999999 -1 >>> -25//4 -7 >>> -13//6 -3 >>> -12//6 -2 >>> -11//6 -2 >>> 0//5 0
-----------
If you are not sure what type a value has, the interpreter can tell you: >>> type(2) <class 'int'> >>> type(42.0) <class 'float'> >>> type('Hello, World!') <class 'str'> In these results, the word “class” is used in the sense of a category; a type is a category of values.
-----------
literalness: Natural languages are full of idiom and metaphor. If I say, “The penny dropped”, there is probably no penny and nothing dropping (this idiom means that someone understood something after a period of confusion). Formal languages mean exactly what they say.
-----------