Python mooc 之玩转数据
Introductions
Key words
Import keyword
Print(keyword.kwlist)
赋值语句
1) 不需要显示声明,根据值来确定类型
2) 以引用的方式赋值
Pythons 数据类型
布尔型:仅有两个数值,分别是ture 和false 分别使用1,0储存
序列类型:
运算顺序
算术运算
power > positive or negative value > multiply or divide > exact division> mode > plus or minus
比较运算
1) 数值比较按大小进行比较
2) 字符串按照ascii 码值大小比较
逻辑运算
-not /and /or. Have the first priorities
The overall priorities(calculation) of calculation
Module, packages, library
Module :
Import modulename ( import single module)
Import modulename1, modulename2, ……(import multiple modules)
Or
From module1 import moduleElement
Package
One package consists a large numbers of modules
Library
One library consists of lots of packages
Module 1
条件
If 语句
Sentence:
If expressions: ( expression means the judgement condition )
Expre_ture_suite ( this means the actions need to carry out when the satisfy the condition)
e.g
if sd1==sd2
print(“the square’s are is “, sd1*sd2)
else
if expression:
expr_true_suite
else:
expr_ture_suite
e.g
sd1=int(input(“the first side:”))
sd2=int(input(“the second side:”))
if sd1==sd2:
print(“ the sqaure’s area is “, sd1*sd2)
else:
print(“the rectangle’s area is”, sd1*sd2)
elif (multiple condition, multiple assumptions)
sentences :
if expression:
expr_true_suite
elif expression2:
expre2_ture_suite
elif expressionN :
exprN_ture_suite
else :
none_of_the_above_s (when the value cannot satisfy any condition above, run this sentence)
e.g
条件嵌套 ( the sequence of running conditional sentence)
e.g
range () [function]
Range(start, end, step)
Not indicate the start, it will be automatically stars from 0
Not indicate the step, it will be automatically be 1
NB: the list of numbers do not include the end value, but it include the stared number
e.g
range(1,6, 1)
[1,2,3,4,5]
Cycle
While
While expression:
Suite_to_repeat
This cycle also can be understand as not-satisfy-end cycle, which means when the value not longer satisfy expression, this cycle stop.
e.g
sumA=0
j=1
while j<10:
sumA+=j
j+=1
sumA
for
for iter_var in iterable_object:
suite_to_repeat
The break, continue and else in the cycle
Break
Break terminate the cycle, and turn to run the next sentence
e.g
网友评论