Python 自动化脚本学习(二)

流程控制


布尔值

temp = True temp = False


比较符号

== != < <= > >=


与或非

and or not


混合布尔的比较

(4<5)and (5<6)


流程控制元素

条件语句 if else

代码块


程序执行


流程描述

if else

if name= John:

  print("my name is John");

esle:

  print("my name is not John");

elif(其它语言的elseif)

 

while 循环

temp = 0

while temp <5 

  print('Hello World')

  temp = temp + 1;

 

break 语句:跳出

continue 语句:跳出本次继续下一次循环

for 循环和range 函数:

for num in range(10)

  total = total + num;

print total;

range 的范围和间隔

for num in range(0,10,2)

  print(num);//0,2,4,6,8

 

for num in range(10,-2,-2)

  print (num);//10,8,6,4,2,0


 导入包

import random

for num in range(3)

  print(random.readint(1,10))/打印三次小于10的随机数字

同时导入多个包:

import random,sys,amth,os


结束程序

sys.exit();

 

posted @ 2015-12-14 12:23  风林火山战  阅读(300)  评论(0编辑  收藏  举报