发表于: 2018-01-12 00:53:24

2 830


今天完成的事:

重新学习python基本概念

逻辑操作符,控制流语句,算数操作符

逻辑操作符:

成员操作符 in

 p=[2,"abc",-1,4.2]

 2 in p

#True

 逻辑运算符

 and or not

 and or 运算符返回决定结果的操作数,在布尔上下文中返回布尔值,not 总是返回布尔值

 a=5

 b=2

 a and b

# 2

 a or b

# 5

 not a

 #False

控制流语句

if语句

 if boolean_expression1:

Suite1

 elif boolean_expression2:

Suite2

 elif boolean_expression3:

Suite3

….

 else:

Suite

 

 while 语句

 while boolean_expression:

Suite

 

 for in 语句

  for variable in iterable:

Suite

 

基本的异常处理

 try

Try_suite

 except exception1 as variable1:

Exception1_suite1

 except exceptionN as variableN:

exceptionN_suite

算数操作符:

基本操作符 + - * /

增强的赋值运算符 +=   *=

 使用增强的赋值操作符是新建一个对象存储结果,变量重新指向该结果,列表除外

列表使用+=时,需要加中括号:

 seeds=[1,2,"a"]

 seeds+=5

#error

 seeds+=[5]

#seeds=[1,2,"a",5]

注意  seeds+="abc"

#seeds=[1,2,"a",5,"a","b","c"]

因此列表推荐使用append()方法



返回列表 返回列表
评论

    分享到