# coding=utf-8
'''
if判断:
>任何非零数字或非空对象都为真
>数字0,空对象以及特殊对象None都是False
'''
result = 1 and 1>2
print result
'''
三中布尔表达式运算
and 与运算(&&)
or 或运算(||)
not 非运算(!)
'''
cond1 = 1
cond2 = 1>2
if cond1 and cond2:
print 'and' #不打印
if cond1 or cond2:
print 'or' #打印
if not cond1:
print 'not'#不打印
#三目运算符
#如果cond1未True,ttt=1否则ttt=2
ttt = 1 if cond1 else 2
print ttt
ttt = 2 if cond2 else 2
print ttt
age = 12;
print 'your age is %d' % age;
if age >=18:
print 'adult';
print 'welcome';
elif age >=6:
print 'young';
else:
print 'kid';
'''
循环:break和continue和其他语言无区别
pass空语句,什么都不执行,占位
else 完全执行完后执行,如果有break不执行
'''
#集合循环
stars = ['Kobe','James','Wade'];
for star in stars:
print star;
'''
range([start,] stop[, step])
range和xrange用法一样,range直接生成list
xrange生成生成器,每次返回其中一个值
'''
a = range(5)
b = xrange(5)
print a,type(b)
for i in range(len(stars)):
print stars[i]
if i>1:
break
else:#不执行该else
print 'over'
for i in xrange(3):pass
sum = 0;
max = 9;
n = 0;
while n<10:
sum += n;
n += 1;
else:
print 'end'
print sum;
1