'''
Created on 2014-10-21
@author: XSD
# strategy #
NOTE:Encoding=UTF-8
'''
#数值类型不同
print(1 == 1.00)
print('a' == 'a ')#比较两个字符串分片所涵盖的内容
print('a' == 'a')
print('# 序列包含的值和顺序相等 | 字典是key和value #')
m = 'ABCDEF'
n = 'ABCABC'
print(m[:-4] == n[3:-1])#string截取
print('# compare #')
print('a' > 'Z')#string比较大小
print('a'.upper() == 'A')
print('AB'.lower())
print("not:", not True)#not 小写 [True | False]
print("not:", not 0)
print("not:", not 'a')
print('# block #')
if 'a' < 'Z':
print('a < Z')
elif False or 1:
print('True')
else:
print('no')
#异常
goods = {'milk':21.0, 'apple':5, 'biscuit':6.3, 'coffee':3.4, 'bread':8.6}
for item in goods.values():
print(goods.keys())
try:
if goods['apple'] > 10:
print('ham:', goods['ham'])
except (KeyError) as error:
print("This is no", error)
break
except (TypeError):
pass
else:print("no exception")
#迭代
w = 1
while w <= 5:
#if w == 5:break
print('w:%d' % w)
w += 1
else:
print('# over')#done: 非break结束迭代后执行
for obj in ('a', 'b', 'c', 'd'):
if obj == 'c' or obj == 'a':
continue
print('obj:', obj)
while True:
num = int(input("input a number:"))
if num == 0:
print('a error number!')
break
for num in range(num, 1, -1):
if num == 4:break
print('n>', num)
Created on 2014-10-21
@author: XSD
# strategy #
NOTE:Encoding=UTF-8
'''
#数值类型不同
print(1 == 1.00)
print('a' == 'a ')#比较两个字符串分片所涵盖的内容
print('a' == 'a')
print('# 序列包含的值和顺序相等 | 字典是key和value #')
m = 'ABCDEF'
n = 'ABCABC'
print(m[:-4] == n[3:-1])#string截取
print('# compare #')
print('a' > 'Z')#string比较大小
print('a'.upper() == 'A')
print('AB'.lower())
print("not:", not True)#not 小写 [True | False]
print("not:", not 0)
print("not:", not 'a')
print('# block #')
if 'a' < 'Z':
print('a < Z')
elif False or 1:
print('True')
else:
print('no')
#异常
goods = {'milk':21.0, 'apple':5, 'biscuit':6.3, 'coffee':3.4, 'bread':8.6}
for item in goods.values():
print(goods.keys())
try:
if goods['apple'] > 10:
print('ham:', goods['ham'])
except (KeyError) as error:
print("This is no", error)
break
except (TypeError):
pass
else:print("no exception")
#迭代
w = 1
while w <= 5:
#if w == 5:break
print('w:%d' % w)
w += 1
else:
print('# over')#done: 非break结束迭代后执行
for obj in ('a', 'b', 'c', 'd'):
if obj == 'c' or obj == 'a':
continue
print('obj:', obj)
while True:
num = int(input("input a number:"))
if num == 0:
print('a error number!')
break
for num in range(num, 1, -1):
if num == 4:break
print('n>', num)