Python的取值
作者:互联网
list1 =[1, 2, 3, 4, 5, 6]
list2 =['a', 'b', 'c', 'd', 'e', ]
list3 =[1, 3, 'a', 'c', True]
print(list1)
print('使用切片方式获取指定list1第三个元素:%d' % list1[3])
print('获取最后一个元素:%d' % list1[-1])
print('获取第一个元素:%s' % list1[:1])
print('获取第2到3的元素:%s' % list1[1:3])
print('获取倒数第三道1:%s' % list1[3:1])
list1.append(2)
# 用1,2,3,4分别组成三位数
num = 0
for a in range(1, 5):
for b in range(1, 5):
for c in range(1, 5):
if a == b or a == c or c == b:
continue
print("{}{}{}".format(a, b, c))
num += 1
s = ['nihao', 'woshi', '???']
s.append('pi')
print(s)
s = ['nihao', 'woshi', '???']
s.insert(2, 'nidaye')
print(s)
s = ['nihao', 'woshi', '???']
s.extend('wodelaojiaaaa')
print(s)
s = ['nihao', 'woshi', '???']
s.pop(0)
print(s)
s = ['nihao', 'woshi', '???']
s.remove('woshi')
print(s)
s = ['nihao', 'woshi', '???']
s.clear()
print(s)
s = ['nihao', 'woshi', '???']
del[s]
s = ['nihao', 'woshi', '???']
del s[0:2]
print(s)
s = ['nihao', 'woshi', '???']
s[1] = 'nihao'
print(s)
li = [1, 2, 3, 4, 5, 'money', 2, 2, 3, 4, 5, 'nihaoa']
li[1] = 'aaaa'
print(li)
li = [1, 2, 3, 4, 5, 'money', 2, 2, 3, 4, 5, 'nihaoa']
li[0:2] = 'a'
print(li)
names = ['de', 'ma', 'xi', 'ya']
print(names[2])
names = ['mike', 'mark', 'candice', 'laular']
print(names[1:3])
print(names[2:])
print(names[:3])
print(names[:])
print(names[-1])
print(names[1:3])
标签:woshi,Python,list1,nihao,li,names,print,取值 来源: https://www.cnblogs.com/zxpnb/p/14275420.html