Book Imformation:
<pratical Programming:an Introduction to Computer science Using Python 3> 2nd edtion
Author:paul Gries,jennifer Campbell,jason Montojo
Page:chapter 2.3 to Chapter 2.5
1.A type consists of things:
(1). A set of values
(2). A set of operations (operation, operation) that can is applied to those values
If an operator (operator) can be applied to more than one type of value,it ' s called an overloaded operator (overloaded operator). /c1>
2.As for floating-point numbers,they is not exactly the fractions (score) learned Before,take 2/3 and 5/3 for ex Ample
1 2/32 0.66666666666666663 5/34 1.6666666666666667
This is fishy (suspicious, questionable): both of them should has an infinite number of 6s after the decimal point. The problem is that computers has finite amount of memory,and the information that can being stored is limited. The number 0.6666666666666666 turns out to being the closest value to 2/3,so as to 5/3.
(question:why the number 0.6666666666666666 turns out to being the closest value to 2/3?)
3.Operator Precedence (operator precedence)
Table 2 shows the order of precedence for arithmetic operators.
It is a good the rule to parenthesize complicated expressions even when you don ' t need to like 1 + 1.7 + (3.2 * 4.4)-(16/3 ), but the use parentheses (parentheses) in the simple expressions such as 3.1 * 5.
If we use 0.6666666666666666 with a calculation, the error may get compounded:
1 >>> 2/3 + 12 1.66666666666666653 >>> 5/34 1.6666666666666667
In many programming languages,1 + 2/3 isn't equal to 5/3.
4.A name, refers to A, value is called variablE (variable).
You create a variable by assigning (Assignment) it a value:
1 >>> Degree_celsius = 26.0
This statement is called assignment statement (Assignment statement).
5.Values, Variables, and computer Memory
In our memory Model,a variable contains the memory address of the object (objects) to which it refers:
We Use the following terminology:
6.augmented Assignment (compound assignment)
Note that the operator are applied after the expression on the right is evaluated:
1 >>> d = 22 >>> D *= 3 + 43 >>> d4 14
7.How Python tells you Something Went wrong
Broadly speaking,there is both kinds of errors in Python:
(1). Syntax errors (syntax error)
Which happen when you type something that isn ' t valid Python code.
e.g.
1 2 " <stdin> " 3 4 5 syntaxerror:invalid syntax
1 >>> = x2 "<stdin>" 3 syntaxerror:can't assign to literal
A literal is any value,like and 26.0
(2). Semantic errors (semantic error)
Which happen when you tells Python to do something the it just can ' t do.
e.g.
1 >>> 3 + Moogah2 "<stdin>" in 3 ' Moogah ' is Not defined
Note 2 for <pratical Programming:an Introduction to Computer science Using Python 3>