variable
Variable name rules:
Variable names consist of letters, numbers, underscores
Variable names can not start with a number
Variable names may have to be descriptive
Variable names are case-sensitive
Variable names prohibit the use of python keyword
Variable names can not use Chinese and Pinyin
Variable names Recommended wording:
- Hump body
- Underline (the official recommended)
2. Constant
- Year-round constant amount
- Variable names in all caps, called Constant
- This python is not constant, as other language needs due.
3. Comment
- A single line (if the line) with annotation #
- Multi-line comments "" "Content" ""
- Three 'and' can
- The content of the comment will not be executed
4. The basic data types acquaintance
- String
- digital
- Boolean value
- List
- Originator
- dictionary
- set
String - str
- For storing some data strings
- In python as long as the string is enclosed in quotes
- "abs" 'skd'
- "" "Sdf" "" is the string assignment, the assignment is not a comment
Digital - int
- For calculating, for comparison
- In the first implementation of the contents of the assignment of the right of the equal sign
- python3: time division returns the decimal (floating point)
- python2: time division returns an integer (rounded down) regardless of an integer number, are integers.
a = "alex"
b = "dsb"
c = a + b # string concatenation
print(c)
a = "alex"+"dsb"*5
print(a)
String +: adding one character string
String *: Multiplying the string
Boolean value --- bool
For judging
True and false judgment
True - true
False - False
User interaction: (input / output)
INPUT () input -----
msg = input ( "precautionary statements")
Pring(msg)
Content input is acquired in a string python3
python2 the input data itself is acquired
type --- View data types
int () ----- casts string to integer
Flow control statements:
Single if
if ---- if
Indent results
if conditions:: statement has ended
Indent official recommended four spaces, or a tab space and tab can not be mixed.
if else a second election
if conditions:
Indent results
else:
Indent results
if elif elif elif a multi-select or deselect
elif - if at
if conditions:
结果
elif condition:
Result
elif condition:
结果
elif condition:
结果
if elif elif elif else a plurality Required
if if if if if a plurality of conditions selected from a plurality of
if conditions:
结果
if conditions:
结果
if conditions:
结果
if conditions:
结果
if nested:
if conditions:
if条件:
Result
== equal Analyzing