一、引号与注释:
1、在python中,不区分单引号(‘ ‘)与双引号(" "),单引号和双引号都可以用来标识字符串。
print("hello")
rint(‘hello‘)
2、单引号与啥U那个引号可以互相嵌套使用,但不能交叉使用。
3、#表示单条注释; 多行注释用但对引号表示。
二、循环
1、if 循环,python通过if语句来实现分支判断,语法: if……else……
a=0
b=1
if a>b:
print(‘a 比较大‘)
else:
print(‘b 比较大‘)
注意:python通过缩进来判断语句体;
if语句通过 == 运算符来判断相等,通过!=运算符来表示不想等;
if语句可以进行布尔类型的判断:
a=true
if a:
print(‘a is true‘)
else:
print(‘a is not true‘)
输出 a is true
if语句多重条件判断:
if score >=90:
print(‘优秀‘)
elif score >=75:
print(‘良好‘)
elif score >=60:
print(‘及格‘)
else:
print(‘不及格‘)
2、for循环
for i in range(10):
print(i)
注意: range(start,end[,step]) range()函数默认从零开始循环,start表示开始位置,end表示结束位置,step标识每一次循环的步长
3、while循环
while count<10:
print(‘hello,world!‘)
count=count+1
else:
print(‘Bye。‘)
break,退出循环,break只能在循环里面用
while count<10:
print(‘hello,world!‘)
count=count+1
if count==5:
break
continue的用法,continue的作用是退出本次循环
while count<10:
print(‘hello,world!‘)
count=count+1
if count==5:
continue
print(‘Bye‘)
、
原文:http://www.cnblogs.com/charlieaml/p/6876249.html