python笔记
异常处理
try:
x=20
y=0
print(x/y)
except BaseException as a:
print(str(a))
finally:
print('this is a test')
if in 语句
# if语句
country='abc'
if country.lower()=='China':
print('you are Chinese')
elif country.lower() in {'usa','abc','def'}:
print('you are bad')
else:
print('not you')
and
#and
m=10
n=20
if m>n and m>10:
print('00000000')
else:
print('11111111')
列表-数组-词典
# 数组
from array import array
sours=array('d')#声明类型
#列表
scorse=[]
scorse.append('aaaa') #添加
scorse.append(12)
scorse.insert(0,'bbb') #插入
print(scorse[0:2])
print(scorse)
#字典
person={'a':'hello'}
person['b']='my'
person['c']='friends'
print(person['a'])
for while循环
#for while循环
for index in range(0,5):
print(index)
for name in ['a','b','c']:
print(name)
index=0
while index<10:
print(index)
index=index+1
函数及其参数
#函数
import datetime
def print_time(name,isUpper):
print(datetime.datetime.now())
if isUpper:
return name[0:2].upper()
else:
return name[0:2]
print(print_time('huang',True))
print(print_time('huang',False))