Python 语句

print语句

f = open('tmp.txt', 'w')

print >> f, "此处放入想写入文件的内容1" , #此处逗号代表写入的两行不换行 只有空格隔开,若没有逗号则写入两行

print >> f, "此处放入想写入文件的内容2"

f.close()

控制流语句

if while for(python 没有switch)

x = 4

if x: ......... 中的 if x == if bool(x)

if elif else

      4 if true else 3(三元表达式) :

if True:
    print 4
else:
    print 3

      while:

x = 1
while True:
     x += 1
     print x
     if x > 20:
          break
else:#while 跑完之后就进入else  但是else 不可以和break 合用 只能和continue 合用
     print ‘end’

       for:

for x in "Hello World !".split(' '):
     print x,#逗号控制输出不换行
else:
print x

布尔值

and or is  ==(检查两端值是否相等) not

原文地址:https://www.cnblogs.com/wlc297984368/p/7582558.html