day05:数组与字典常识(20170217)

#1:数组功能的使用:
print ("a4A".isdecimal()) #
print ("18".isdigit()) #判断是否是数字
print ("a 1A".isidentifier()) #判断是否是合法的标识符
print ("33".isnumeric()) #是否是数字?
print ("Name".istitle()) #第一个字母是否大写(标题,仅看第一个)
print ("NAME".isupper()) #判断是否是大写字母
print ("namess".islower()) #判断是否是小写字母
print ("NA ME".isprintable()) #??
print ('+'.join(['1','2','5']))
print (' Alex'.lstrip())
print ('Alex '.rstrip())
print (' Alex '.strip())
p = str.maketrans("fghij",'12345')
p1 = str.maketrans("56##9",'12345')
print (p)
print (p1)
print("alexhij".translate(p)) #替代相同的部分
print('alex lYY'.replace('l','YE',1)) #第一次出现的l修改为"YE"
print('a33le445xli'.rfind("5")) #???
print('1+2+3+4+5'.split('+')) #按+号进行拆分排列
print('1+2 +3+4+5'.splitlines()) #按 号位置进行拆分排列

#2:字典常识:
test = ['01':'小李','02':'杨兴','03':'小明']
print(test)

test = {'a01':'小李','a02':'杨兴','a03':'小明'}
print (test) #打印字典
print(test["a01"]) #打印索引编号为a01的数据
test['a01'] = '大兵' #修改a01为“大兵”
print(test['a01'])
del test['a02'] #删除数据"a02"
test['a04'] = '大海' #插入数据a04
print(test['a04'])
print(test)
test.pop('a04') #最好的删除方式(没有编号a04的数据也不会报错)
print(test)

test02 = {'b01':'xiaohua','a03':'xiaoming'}
test.update(test02) #合并和更新数据。
print (test)

————————————————————————————运行结果如下————————————————————————————————————————————

False
True
False
True
True
True
True
True
1+2+5
Alex
Alex
Alex
{102: 49, 103: 50, 104: 51, 105: 52, 106: 53}
{53: 49, 54: 50, 35: 52, 57: 53}
alex345
aYEex lYY
7
['1', '2', '3', '4', '5']
['1+2', '+3+4+5']
{'a01': '小李', 'a02': '杨兴', 'a03': '小明'}
小李
大兵
大海
{'a01': '大兵', 'a03': '小明', 'a04': '大海'}
{'a01': '大兵', 'a03': '小明'}
{'a01': '大兵', 'a03': 'xiaoming', 'b01': 'xiaohua'}



原文地址:https://www.cnblogs.com/liulvzhong/p/6411063.html