Python 符号 自学总结(学习中)

来源:互联网 发布:方舟生存进化画面优化 编辑:程序博客网 时间:2024/06/16 09:19

(一)关键字
①逻辑符号 and,not or

**And**1 and 1    #Trueif (1 and zero)   #下列语句不执行    .......**Not**1.a = Falseif not a     print "You did it" 2.a = 20b = [1 2 4 8 16 32]if a not in b    print  "We can't find a in b."  **or**1 or 0  #True

② del

a = 5b = a del aprint (b) #del函数只是删除了变量,并没有删除数据 

③from, import

from sys import .... #目前只学到了这个用法,从某处导入……import #导入

④while

while(expression):    excute....... #循环,当!expression时退出

⑤as

import some as other  #some为库函数,但调用时不想直接用其名字,可as为other,使用时直接调用other,作用同some

⑥if elif else

if (expression):    ..........elif (expression):    ..........else (expression):    ..........       #三者表达式写法相近,if 一定要有

⑦global

a = 10def something():    global a    a = 20    print "Here a = %d\n" %aprint "We can see a now is %d\n" %asomething()print "Now the a is %d" %a
#这里代码运行结果如下We can see a now is 10Here a = 20Now the a is 20

⑧ with(待更新)
⑨assert(待更新)
⑩pass

if (expression)    pass #暂时跳过

⑪yield(待更新)
⑫except(待更新)
⑬class(待更新)
⑭exec(待更新)






自学起步,写此博客作为总结及查缺补漏用,如果各位dalao发现博客里的错误,欢迎纠正。谢谢!