Section 2 (2)
2.1.5 Variables
Variable: the intermediate result of the operation to the temporary memory, for subsequent transfer Using procedures.
Variable naming rules:
1. Variable letters, numbers, underscores combinations into ⽽
2. Use beginning not digital, not all digital
3. You can not use python keywords, these symbols and letters have been occupied python, can not be changed
4. Do not Use Chinese or Pinyin
The variable names to be meaningful
6. do not need too long
7. Write distinguish zoomed ⼩
8. recommended
驼峰体: 除首字母外的其他每个单词首字母⼤写
下划线: 每个单词之间用下划线分开
2.2.6 Constant
Absolute constants do not exist in python. Convention, all uppercase characters ⺟ is constant, you can change but not to change
such as: PI = 3.141592653
BIRTH_OF_SYLAR = 1990
2.2.7 Notes
Single-line comments: # annotated content
Multiline comments: '' 'content is annotated' '' '' 'This is a multi-line comments "" "
In fact, the comment is not quoted strings, so there is not referenced does not run
2.2.8 Python basic data types
Although very large computer zoomed, but some degree ⻆ silly point of view, in addition comes in handy you explicitly tell it, is the number 1, "Han" is the word, otherwise it is the difference and "Han" is hard to tell 1 and, therefore, in your language and in each program will have a data type of stuff is called, in fact, a variety of frequently-used data types into ⾏ a clear division. There are many types of data often Use with Python.
1. integer (int)
The numbers are often ⻅ int type, the calculation or comparison Use zoomed smaller size
int on 32-bit machines are: -2 * 31 ~ 2 * 31-1, i.e. ~ 2147483647 -2147483648
int on 64-bit machines are: -2 * 63 ~ 2 * 63-1, i.e. -9223372036854775808 ~ 9223372036854775807
Note that these are integers.
2. The string (str)
In Python, all Using quotation marks, and all strings.
Using single string string may double quotation marks, or three quotation marks.
Would like to ⾏ trekking assignment ⼀ a string string, you need three quotes.
Multiplying the added character string can be, but does not allow subtraction and division:
+ String when the string is adding to
Multiplying the string and the string *
3. Boolean value (bool)
True or False, True and False.
Note that with or and and fit
2.2.9 User interaction
Use input ( 'prompt') function, it allows us to interact with computers up
Content = the INPUT ( 'prompt'), you can get directly to the contents Using the user input, the default is to obtain the string type, see here speak a command element type of print (type ()),
2.2.10 If flow control statements
First Time kinds of syntax :
if 条件: #引号是将条件与结果分开。
结果1 # 四个空格,这个是告诉程序满⾜这个条件后执行的语句
结果2
If the condition is true (True) Perform a result, then the result of 2, if the conditions are false (False) as a direct result 2
Second shot kinds of syntax: **
If 条件:
结果1
else:
结果2
代码3
The third syntax:
If 条件1:
结果1
elif 条件2:
结果2
..
else:
结果n
The fourth syntax:
If 条件1:
结果1
if 条件2:
结果2
If 条件3:
结果3
if 条件4:
结果4
else:
结果n
The fifth grammar (nested):
If 条件1:
结果1
If 条件2:
结果2
else:
结果3
else:
结果4
Unlimited nesting, but in the actual development. Try not to exceed the amount of three nested, and note the space, the space does not directly lead to operational errors
-While loop flow control
while 条件:
结果
If the condition is true, direct execution results and then determine the condition again until the condition is false, stop the cycle stop
The end of the cycle:
1. Change the conditions.
2.break
2.211 and continue process control -break
1.break:. Immediately out of the cycle interrupt means
2.continue: Stop this cycle, the next cycle continues
Note also the use of pass: the implementation of the statement part of the idea is not yet complete, then you can use the pass statement placeholder, may also be used as a marker to the code had completed later