@c4tman
##tuple
print('##tuple##')
tuple = (1,2,3,'12312',1)
print('lenght: ', len(tuple))
print('index[0]: ', tuple[0])
print('index[-1]: ', tuple[-1])
for t in tuple:
print(t, ' ', end='')
print()
##list
print('##list##')
myList = [1,2,3,4,5,6,7, 'Bob']
print('length: ', len(myList))
print('index[0]: ', myList[0])
print('index[-1]: ', myList[-1])
for i in myList:
print(i, ' ', end = "")
print()
myList.append(10)
myList.pop(0)
myList[0] = -1
for i in myList:
print(i, ' ', end = "")
print()
myList.clear()
##set
print('##set##')
mySet = set([1,2,3,4,5,6])
print('length: ', len(mySet))
print('key 8 in mySet: ', 8 in mySet)
mySet.add(8)
mySet.remove(8)
s1 = set([1,2,3])
s2 = set([2,3,4])
print('s1&s2: ', s1 & s2)
print('s1|s2: ', s1 | s2)
for s in mySet:
print(s, ' ', end = '')
mySet.clear()
print()
##dict
print('##dict##')
myDict = {'A':1, 'B':2, 'C':3}
print('length: ', len(myDict))
print('key A in dict: ', 'A' in myDict)
print('value in \'A\': ', myDict['A'])
myDict['D'] = 4
print('value in \'D\': ', myDict.get('D'))
print('-1 if key \'E\' not exist: ', myDict.get('E', -1))
myDict.pop('D')
for key in myDict.keys():
print(key, ' : ',myDict.get(key))
Chapter1 集合基本操作
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...