2019/2/1Python LS1下午的数组(列表)

'''
Array数组/List列表
1、append 后面追加
remove去除

'''
# ages = [30,19,19,8,43]
# ages.append(3)
# names = ['LSS','HLT','HLC','CJW','CMF']
# print(ages)
# print(dir(ages))
things = ['rope','cup','bag','ball']
things.append('papercup')
#用dir来看所有的操作
print(dir(things))
#用type来看东西类型
print(type(things))
# 可以用things.clear()来移除数组中所有的元素

#用数组名.remove('')来移除某个元素
things.remove('ball')

#用len计算数组长度
print(len(things))
#count表示出现几次
print(things.count('ball'))
#Pop+下标移除对应的值
things.pop(0)
print(things)
print(things.index('bag'))
#insert(要加入的位置,'')
things.insert(1,'ball')
print(things)
#可以用things.extend来将第二个数组拓展到第一个数组中
goods = [1,4,1]
things.extend(goods)
print(things)
#重新赋值来替换
things[1] = 'basketball'
print(things)

猜你喜欢

转载自www.cnblogs.com/HuangLTthebest/p/10345975.html